pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
898 stars 120 forks source link

Question: binding class to global object #40

Closed jcmonnin closed 7 years ago

jcmonnin commented 7 years ago

Hi,

I need do a binding on an existing codebase. The resulting JavaScript interface needs to be compatible to what we had before (it was using QtScript).

Some classes are added directly in the global scope of JavaScript (ie. var x = X() instead of var x = module.X())

A module is added that way:

isolate->GetCurrentContext()->Global()->Set(v8::String::NewFromUtf8(isolate, "module"), module.new_instance());

I have not found a way to achieve the same using a v8pp::class_. There is no new_instance method in it.

Is there a way to achieve what I want?

pmed commented 7 years ago

Hi,

Well, I've never used class in this way, and may only suggest now to try `v8pp::class::js_function_template()->GetFunction()` to get the class constructor function instance.

Maybe you also have to set manually the class name: v8pp::class_<T>::.class_function_template()->SetClassName(...)

jcmonnin commented 7 years ago

Thanks. I could make it work that way.