Changeset View
Changeset View
Standalone View
Standalone View
source/scriptinterface/FunctionWrapper.h
Show First 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | #endif | ||||
static bool CallVoid(const ScriptRequest& rq, JS::HandleValue val, const char* name, const Args&... args) | static bool CallVoid(const ScriptRequest& rq, JS::HandleValue val, const char* name, const Args&... args) | ||||
{ | { | ||||
return Call(rq, val, name, IgnoreResult, std::forward<const Args>(args)...); | return Call(rq, val, name, IgnoreResult, std::forward<const Args>(args)...); | ||||
} | } | ||||
/** | /** | ||||
* Return a function spec from a C++ function. | * Return a function spec from a C++ function. | ||||
*/ | */ | ||||
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> | template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr> | ||||
static JSFunctionSpec Wrap(const char* name) | static JSFunctionSpec Wrap(const char* name, | ||||
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) | |||||
{ | { | ||||
return JS_FN(name, (&ToJSNative<callable, thisGetter>), 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. | * Return a JSFunction from a C++ function. | ||||
*/ | */ | ||||
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> | template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr> | ||||
static JSFunction* Create(const ScriptRequest& rq, const char* name) | static JSFunction* Create(const ScriptRequest& rq, const char* name, | ||||
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) | |||||
{ | { | ||||
return JS_NewFunction(rq.cx, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags, name); | return JS_NewFunction(rq.cx, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags, name); | ||||
} | } | ||||
/** | /** | ||||
* Register a function on the native scope (usually 'Engine'). | * Register a function on the native scope (usually 'Engine'). | ||||
*/ | */ | ||||
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> | template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr> | ||||
static void Register(const ScriptRequest& rq, const char* name) | static void Register(const ScriptRequest& rq, const char* name, | ||||
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) | |||||
{ | { | ||||
JS_DefineFunction(rq.cx, rq.nativeScope, name, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags); | JS_DefineFunction(rq.cx, rq.nativeScope, name, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags); | ||||
} | } | ||||
/** | /** | ||||
* Register a function on @param scope. | * Register a function on @param scope. | ||||
* Prefer the version taking ScriptRequest unless you have a good reason not to. | * Prefer the version taking ScriptRequest unless you have a good reason not to. | ||||
* @see Register | * @see Register | ||||
*/ | */ | ||||
template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr, u16 flags = JSPROP_ENUMERATE|JSPROP_READONLY|JSPROP_PERMANENT> | template <auto callable, GetterFor<decltype(callable)> thisGetter = nullptr> | ||||
static void Register(JSContext* cx, JS::HandleObject scope, const char* name) | static void Register(JSContext* cx, JS::HandleObject scope, const char* name, | ||||
const u16 flags = JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) | |||||
{ | { | ||||
JS_DefineFunction(cx, scope, name, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags); | JS_DefineFunction(cx, scope, name, &ToJSNative<callable, thisGetter>, args_info<decltype(callable)>::nb_args, flags); | ||||
} | } | ||||
}; | }; | ||||
#endif // INCLUDED_FUNCTIONWRAPPER | #endif // INCLUDED_FUNCTIONWRAPPER |
Wildfire Games · Phabricator