From 12c051a51f33345e2dbe3eee90fb3c919c4e2557 Mon Sep 17 00:00:00 2001 From: nitrocaster Date: Thu, 26 Nov 2015 02:11:36 +0300 Subject: [PATCH] Add default_converter and type_to_string specs for functor. --- src/xrScriptEngine/Functor.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/xrScriptEngine/Functor.hpp b/src/xrScriptEngine/Functor.hpp index 4d6e3cec2d3..3b2c00b75ff 100644 --- a/src/xrScriptEngine/Functor.hpp +++ b/src/xrScriptEngine/Functor.hpp @@ -2,6 +2,7 @@ #include "xrScriptEngine/xrScriptEngine.hpp" #include +#include namespace luabind { @@ -21,4 +22,32 @@ template<> template void functor::operator()(Args &&...args) const { call_function(*static_cast(this), std::forward(args)...); } + +namespace detail +{ +template +struct type_to_string> +{ + static void get(lua_State *L) + { + lua_pushstring(L, "function<"); + type_to_string::get(L); + lua_pushstring(L, ">"); + lua_concat(L, 3); + } +}; +} + +template +struct default_converter> : native_converter_base> +{ + static int compute_score(lua_State *luaState, int index) + { return lua_type(luaState, index)==LUA_TFUNCTION ? 0 : -1; } + + functor from(lua_State *luaState, int index) + { return object(from_stack(luaState, index)); } + + void to(lua_State *luaState, const functor &func) + { func.push(luaState); } +}; }