我正在尝试将函数硬编码为字符串,将其转换为函数并运行它。
Local<Function> cb = "function(){ console.log('HELLO BOSS'); }";
int argc=0;
v8::Handle<v8::Value> * argv;
cb->Call(Context::GetCurrent()->Global(),argc,argv);
编译器sais我不能直接这样做:
error C2664: 'v8::Handle<T>::Handle(T *)' : cannot convert parameter 1 from 'const char *' to 'v8::Function *'
with
[
T=v8::Function
]
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
x.cpp(15) : see reference to function template instantiation 'v8::Local<T>::Local<const char>(S *)' being compiled
with
[
T=v8::Function,
S=const char
]
我怎么能这样做呢?此外,所有的好东西(评估,新功能等)在哪里?
答案 0 :(得分:2)
我做到了。男孩,我喜欢这个东西。
v8::Script::Compile(v8::String::New(
" console.log('WORKS BOSS'); "
" console.log('Happy?'); "
" console.log('2+2=' + (2+2)); "
))->Run();
我不知道它是否正确(正如“任何相关风险”一样),但似乎有效。