mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Simplify GUI Proxy implementation & customisation.
This finishes7c04ea0211and1b67a079fb. GUI Proxy objects are now easier to specialize, code duplication is reduced, code is made safer. In details: - the proxy private is always the IGUIObject* pointer - the private data is accessed through a safer wrapper - CreateJSObject returns an opaque type to allow easier extension & prevent errors. - The implementation of CreateJSObject is moved near the GUI Proxy template instantiation, and both are wrapped in a convenient macro (this makes it so that if you use the macro, you can't forget to overload the method, and vice-versa). - The common IGUIObject JS interface no longer needs to be repeated. - All specialisations are again put in the same file, for improved compile-time & clarity, given there are so few lines now. - While at it, implement toSource which makes it possible to `uneval` components (does the same as toString though). Differential Revision: https://code.wildfiregames.com/D3826 This was SVN commit r25225.
This commit is contained in:
@@ -285,7 +285,16 @@ public:
|
||||
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT>
|
||||
static JSFunctionSpec Wrap(const char* name)
|
||||
{
|
||||
return JS_FN(name, (&ToJSNative<callable>), args_info<decltype(callable)>::nb_args, flags);
|
||||
return JS_FN(name, (&ToJSNative<callable, thisGetter>), args_info<decltype(callable)>::nb_args, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a JSFunction from a C++ function.
|
||||
*/
|
||||
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT>
|
||||
static JSFunction* Create(const ScriptRequest& rq, const char* name)
|
||||
{
|
||||
return JS_NewFunction(rq.cx, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags, name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user