-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to export static constants? #84
Comments
I would suggest the following proposal for class.hpp:
So you can define (const) static members this way:
|
Hi,
I can’t check it now, but what if just add the constant value into
`class_info_.js_function_template()` inside of `set_const()` function,
similar to the `set()` implementation for static functions.
пт, 24 авг. 2018 г. в 13:14, VitaminCpp <notifications@github.com>:
I would suggest the following proposal for class.hpp:
/// Set a static value
template<typename Value>
class_& set_static(char const* name, Value const& value, bool readonly = false)
{
v8::HandleScope scope(isolate());
class_info_.js_function_template()->GetFunction(isolate()->GetCurrentContext()).ToLocalChecked()
->DefineOwnProperty(isolate()->GetCurrentContext(),
v8pp::to_v8(isolate(), name), to_v8(isolate(), value),
v8::PropertyAttribute(v8::DontDelete | (readonly ? v8::ReadOnly : 0))).FromJust();
return *this;
}
So you can define (const) static members this way:
MyClassWrapper myClassWrapper(isolate);
myClassWrapper
.ctor<MyClass::Type>()
.set_static("MY_CONSTANT", &MyClass::MY_READONLY_CONSTANT, true)
.set_static("MY_CONSTANT", &MyClass::MY_CONSTANT);
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#84 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABEgUr9UvMuoVZlLmwtBDg87lxz1o2EWks5uT9IGgaJpZM4WK8Ln>
.
--
Sincerely,
Pavel
|
Hi @pmed, if I understood you right that would mean that every variable set through set_const would be accessible without a class instantiation. Furthermore the static variable would only available as const variable and for some applications there is maybe a need of writable static variables. So I think it would be best if there is a seperate set of functions which register either member variables (const or writeable) or static variables (const or writeable) of a class like @VitaminCpp made an example of. Regards, |
Fixed in #89, but note that static property definition works only at the end of |
I would like to write the following Javascript:
My current class wrapper looks like this:
But as expected this wont work, because MY_CONSTANT is a V8 prototype property instead of a V8 ObjectTemplate property.
But because I can't break our current API, I would need some workaround without having to change my existing API.
The text was updated successfully, but these errors were encountered: