| 22 | // Register a function. |
| 23 | template<typename RetType, typename... Ts> |
| 24 | void dukglue_register_function(duk_context* ctx, RetType(*funcToCall)(Ts...), const char* name) |
| 25 | { |
| 26 | duk_c_function evalFunc = dukglue::detail::FuncInfoHolder<RetType, Ts...>::FuncRuntime::call_native_function; |
| 27 | |
| 28 | duk_push_c_function(ctx, evalFunc, sizeof...(Ts)); |
| 29 | |
| 30 | static_assert(sizeof(RetType(*)(Ts...)) == sizeof(void*), "Function pointer and data pointer are different sizes"); |
| 31 | duk_push_pointer(ctx, reinterpret_cast<void*>(funcToCall)); |
| 32 | duk_put_prop_string(ctx, -2, "\xFF" "func_ptr"); |
| 33 | |
| 34 | duk_put_global_string(ctx, name); |
| 35 | } |