本文整理汇总了C++中KObjectRef类的典型用法代码示例。如果您正苦于以下问题:C++ KObjectRef类的具体用法?C++ KObjectRef怎么用?C++ KObjectRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KObjectRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
AutoPtr<StaticBoundObject> ScopeMethodDelegate::CreateDelegate(KObjectRef global, KObjectRef bo)
{
AutoPtr<StaticBoundObject> scope = new StaticBoundObject();
SharedStringList keys = bo->GetPropertyNames();
StringList::iterator iter = keys->begin();
while(iter!=keys->end())
{
SharedString key_ptr = (*iter++);
std::string key = *key_ptr;
KValueRef value = bo->Get(key.c_str());
if (key == "set")
{
KMethodRef d = new ScopeMethodDelegate(SET, global, scope, value->ToMethod());
KValueRef v = Value::NewMethod(d);
scope->Set(key.c_str(), v);
}
else if (key == "get")
{
KMethodRef d = new ScopeMethodDelegate(GET, global, scope, value->ToMethod());
KValueRef v = Value::NewMethod(d);
scope->Set(key.c_str(), v);
}
else
{
scope->Set(key.c_str(), value);
}
}
return scope;
}
示例2: Evaluate
KValueRef Script::Evaluate(const char *mimeType, const char *name, const char *code, KObjectRef scope)
{
KObjectRef evaluator = this->FindEvaluatorWithMethod("canEvaluate", mimeType);
if (!evaluator.isNull())
{
KMethodRef evaluate = evaluator->GetMethod("evaluate");
if (!evaluate.isNull())
{
ValueList args;
args.push_back(Value::NewString(mimeType));
args.push_back(Value::NewString(name));
args.push_back(Value::NewString(code));
args.push_back(Value::NewObject(scope));
return evaluate->Call(args);
}
else
{
throw ValueException::FromFormat(
"Error evaluating: No \"evaluate\" method found on evaluator for mimeType: \"%s\"", mimeType);
}
}
else
{
throw ValueException::FromFormat("Error evaluating: No evaluator found for mimeType: \"%s\"", mimeType);
}
}
示例3: MergePyGlobalsWithContext
static void MergePyGlobalsWithContext(PyObject* globals, KObjectRef context)
{
// Avoid compiler warnings
PyObject *items = PyObject_CallMethod(globals, (char*) "items", NULL);
if (items == NULL)
return;
PyObject *iterator = PyObject_GetIter(items);
if (iterator == NULL)
return;
PyObject *item;
while ((item = PyIter_Next(iterator)))
{
PyObject* k = PyTuple_GetItem(item, 0);
PyObject* v = PyTuple_GetItem(item, 1);
std::string sk = PythonUtils::ToString(k);
if (sk.find("__") != 0)
{
KValueRef newValue = PythonUtils::ToKrollValue(v);
KValueRef existingValue = context->Get(sk.c_str());
if (!newValue->Equals(existingValue))
{
context->Set(sk.c_str(), newValue);
}
}
Py_DECREF(item);
}
}
示例4: PreprocessURLCallback
char* PreprocessURLCallback(const char* url, KeyValuePair* headers, char** mimeType)
{
Logger* logger = Logger::Get("UI.URL");
KObjectRef scope = new StaticBoundObject();
KObjectRef kheaders = new StaticBoundObject();
while (headers->key)
{
kheaders->SetString(headers->key, headers->value);
headers++;
}
try
{
AutoPtr<PreprocessData> result =
Script::GetInstance()->Preprocess(url, scope);
*mimeType = strdup(result->mimeType.c_str());
return strdup(result->data->Pointer());
}
catch (ValueException& e)
{
logger->Error("Error in preprocessing: %s", e.ToString().c_str());
}
catch (...)
{
logger->Error("Unknown Error in preprocessing");
}
return NULL;
}
示例5: PropertiesBinding
void AppBinding::CreateProperties(const ValueList& args, KValueRef result)
{
AutoPtr<PropertiesBinding> properties = new PropertiesBinding();
result->SetObject(properties);
if (args.size() > 0 && args.at(0)->IsObject())
{
KObjectRef p = args.at(0)->ToObject();
SharedStringList names = p->GetPropertyNames();
for (size_t i = 0; i < names->size(); i++)
{
KValueRef value = p->Get(names->at(i));
ValueList setterArgs;
setterArgs.push_back(Value::NewString(names->at(i)));
setterArgs.push_back(value);
PropertiesBinding::Type type;
if (value->IsList()) type = PropertiesBinding::List;
else if (value->IsInt()) type = PropertiesBinding::Int;
else if (value->IsDouble()) type = PropertiesBinding::Double;
else if (value->IsBool()) type = PropertiesBinding::Bool;
else type = PropertiesBinding::String;
properties->Setter(setterArgs, type);
}
}
}
示例6: Configure
void Notification::Configure(KObjectRef properties)
{
this->title = properties->GetString("title");
this->message = properties->GetString("message");
this->iconURL = properties->GetString("icon");
this->timeout = properties->GetInt("timeout", -1);
this->clickedCallback = properties->GetMethod("callback");
}
示例7: Stop
void RubyModule::Stop()
{
KObjectRef global = this->host->GetGlobalObject();
global->Set("Ruby", Value::Undefined);
Script::GetInstance()->RemoveScriptEvaluator(this->binding);
this->binding = NULL;
RubyModule::instance_ = NULL;
ruby_cleanup(0);
}
示例8: _SetContextMenu
void UIBinding::_SetContextMenu(const ValueList& args, KValueRef result)
{
args.VerifyException("setContextMenu", "o|0");
KObjectRef argObj = args.GetObject(0, NULL);
AutoMenu menu = NULL;
if (!argObj.isNull())
{
menu = argObj.cast<Menu>();
}
this->SetContextMenu(menu);
}
示例9: SG
void PHPModule::InitializeBinding()
{
PHPModule::mimeType = SG(default_mimetype);
KObjectRef global = this->host->GetGlobalObject();
this->binding = new PHPEvaluator();
global->Set("PHP", Value::NewObject(this->binding));
Script::GetInstance()->AddScriptEvaluator(this->binding);
zval *titaniumValue = PHPUtils::ToPHPValue(Value::NewObject(global));
ZEND_SET_SYMBOL(&EG(symbol_table), PRODUCT_NAME, titaniumValue);
}
示例10: InitializeBinding
void RubyModule::InitializeBinding()
{
// Expose the Ruby evaluator into Kroll
KObjectRef global = this->host->GetGlobalObject();
this->binding = new RubyEvaluator();
global->Set("Ruby", Value::NewObject(binding));
Script::GetInstance()->AddScriptEvaluator(this->binding);
// Bind the API global constant
VALUE ruby_api_val = RubyUtils::KObjectToRubyValue(Value::NewObject(global));
rb_define_global_const(PRODUCT_NAME, ruby_api_val);
}
示例11: StaticBoundObject
KObjectRef Process::CloneEnvironment()
{
SharedStringList properties = environment->GetPropertyNames();
KObjectRef clonedEnvironment = new StaticBoundObject();
for (size_t i = 0; i < properties->size(); i++)
{
std::string property = *properties->at(i);
std::string value = environment->Get(property.c_str())->ToString();
clonedEnvironment->Set(property.c_str(), Value::NewString(value.c_str()));
}
return clonedEnvironment;
}
示例12: GetContextId
static string GetContextId(KObjectRef global)
{
string contextId(global->GetString("__php_module_id__"));
if (contextId.empty())
{
static int nextId = 0;
contextId.append("__kroll__namespace__");
contextId.append(KList::IntToChars(++nextId));
global->SetString("__php_module_id__", contextId);
}
return contextId;
}
示例13: Start
void PlatformModule::Start()
{
// Duplicate the network module address, macaddress and interfaces here for
// backward compatibility. The network module should be initialized when
// Start() is called.
if (!GlobalObject::GetInstance()->GetObject("Network").isNull())
{
KObjectRef network = GlobalObject::GetInstance()->GetObject("Network");
this->binding->Set("getAddress", network->Get("getAddress"));
this->binding->Set("getMACAddress", network->Get("getMACAddress"));
this->binding->Set("getInterfaces", network->Get("getInterfaces"));
}
}
示例14: StaticBoundObject
void HttpServerRequest::GetHeaders(const ValueList& args, KValueRef result)
{
Poco::Net::HTTPServerRequest::ConstIterator iter = request.begin();
KObjectRef headers = new StaticBoundObject();
for(; iter != request.end(); iter++)
{
std::string name = iter->first;
std::string value = iter->second;
headers->SetString(name.c_str(), value.c_str());
}
result->SetObject(headers);
}
示例15: Stop
void PHPModule::Stop()
{
PHPModule::instance_ = NULL;
KObjectRef global = this->host->GetGlobalObject();
Script::GetInstance()->RemoveScriptEvaluator(this->binding);
global->Set("PHP", Value::Undefined);
this->binding->Set("evaluate", Value::Undefined);
this->binding = 0;
PHPModule::instance_ = 0;
php_embed_shutdown(TSRMLS_C);
}