在 v8 中将字符串转换为函数
Convert string to function in v8
我正在尝试将函数硬编码为字符串,将其转换为函数并运行它。
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
]
那我该怎么做呢?另外,所有好东西(评估,新功能等)在哪里?
我做到了。男孩,我喜欢这个东西。
v8::Script::Compile(v8::String::New(
" console.log('WORKS BOSS'); "
" console.log('Happy?'); "
" console.log('2+2=' + (2+2)); "
))->Run();
我不知道它是否正确(就像"任何相关的风险"一样),但它似乎有效。
相关文章:
- 转换函数,将 std::数组的双精度作为参数或双精度作为参数单独转换
- C++:用户定义的显式类型转换函数错误
- 为什么下面带有非常量转换函数的代码没有歧义?
- 为什么转换函数声明不需要至少一个定义类型说明符
- PCL:当我在setConditionFunction中使用std::bind 时,没有合适的转换函数
- C++ 通过自定义赋值运算符隐式转换函数参数
- 当我使用 void 函数的返回值(通过强制转换函数指针)时,究竟会发生什么?
- 在C++中自动向下转换函数参数
- static_cast:转换函数模板——它们真的有效吗
- 通过像printf这样的可变参数函数传递一个带有常量字符*转换函数的类
- 隐式转换函数的返回对象时是否会影响性能?
- C++不存在合适的转换函数
- 为什么允许 int 和 const int 使用不同的转换函数?
- 使用转换函数直接初始化
- 为什么用户定义的转换函数模板不能有推导的返回类型?
- 为什么我会收到转换函数错误
- 选择用于赋值初始化的转换函数的优先级
- 我收到错误:没有合适的转换函数从 std::basic_istream<char、std::char_traits<char>> 到 char 存在
- 具有转换函数的 lambda,指向具有 C++ 链接的函数的指针
- 使用模板和部分专用化生成类型转换函数