diff --git a/src/luaexport/LuaFunction.hpp b/src/luaexport/LuaFunction.hpp index 9f2c8b1..cf8e484 100644 --- a/src/luaexport/LuaFunction.hpp +++ b/src/luaexport/LuaFunction.hpp @@ -7,6 +7,7 @@ #ifndef LUA_FUNCTION_HPP_INCLUDED #define LUA_FUNCTION_HPP_INCLUDED LUA_FUNCTION_HPP_INCLUDED +#include #include #include #include @@ -67,6 +68,44 @@ struct LuaFunction luabind::object m_func; }; +namespace luabind { + template + struct default_converter> + : native_converter_base> + { + typedef boost::function FType; + typedef typename FType::result_type FResultType; + static int compute_score(lua_State* L, int index) + { + if (lua_type(L, index) == LUA_TFUNCTION) + return 1; + if (luaL_getmetafield(L, index, "__call")) { + lua_pop(L, 1); + return 0; + } + return -1; + } + + FType from(lua_State* L, int index) + { + return LuaFunction( + luabind::object(from_stack(L, index))); + } + + //void to(lua_State* L, FType value); not supported + }; + + template + struct default_converter const> + : default_converter> + {}; + + template + struct default_converter const&> + : default_converter> + {}; +} // namespace luabind + #endif // include guard