2012-06-18 1 views
1

문자열로 함수를 하드 코딩하고 함수로 변환하여 실행하려고합니다.문자열을 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 
     ] 

방법은 다음을 할 수 있습니까? 또한, 모든 장점 (eval, 새로운 기능 등)은 어디에 있습니까?

답변

2

내가 해냈어. 소년 나는이 물건을 좋아한다.

v8::Script::Compile(v8::String::New(
    " console.log('WORKS BOSS'); " 
    " console.log('Happy?'); " 
    " console.log('2+2=' + (2+2)); " 
))->Run(); 

맞는지 ("위험과 관련이 있습니다"와 같음) 모르지만 작동하는 것으로 보입니다.

+0

자신에게 가장 적합한 답변을 수락하는 것이 좋습니다. –

+1

@EitanT에서 2 일 후 –