void KObject::SetNS(const char *name, SharedValue value) { std::vector<std::string> tokens; FileUtils::Tokenize(std::string(name), tokens, "."); KObject *scope = this; for (size_t i = 0; i < tokens.size() - 1; i++) { const char* token = tokens[i].c_str(); StaticBoundObject *next; SharedValue next_val = scope->Get(token); if (next_val->IsUndefined()) { next = new StaticBoundObject(); SharedKObject so = next; next_val = Value::NewObject(so); scope->Set(token, next_val); scope = next; } else if (!next_val->IsObject() && !next_val->IsMethod() && !next_val->IsList()) { std::cerr << "invalid namespace for " << name << ", token: " << token << " was " << next_val->GetType() << std::endl; throw Value::NewString("Invalid namespace on setNS"); } else { scope = next_val->ToObject().get(); } } const char *prop_name = tokens[tokens.size()-1].c_str(); scope->Set(prop_name, value); #ifdef DEBUG_BINDING std::cout << "BOUND: " << value->GetType() << " to: " << name << std::endl; #endif }