Skip to content

Commit 12c051a

Browse files
author
nitrocaster
committed
Add default_converter and type_to_string specs for functor.
1 parent fe7bc5f commit 12c051a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/xrScriptEngine/Functor.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "xrScriptEngine/xrScriptEngine.hpp"
44
#include <type_traits>
5+
#include <luabind/detail/format_signature.hpp>
56

67
namespace luabind
78
{
@@ -21,4 +22,32 @@ template<>
2122
template<typename... Args>
2223
void functor<void>::operator()(Args &&...args) const
2324
{ call_function<void>(*static_cast<const adl::object *>(this), std::forward<Args>(args)...); }
25+
26+
namespace detail
27+
{
28+
template<typename T>
29+
struct type_to_string<functor<T>>
30+
{
31+
static void get(lua_State *L)
32+
{
33+
lua_pushstring(L, "function<");
34+
type_to_string<T>::get(L);
35+
lua_pushstring(L, ">");
36+
lua_concat(L, 3);
37+
}
38+
};
39+
}
40+
41+
template<typename T>
42+
struct default_converter<functor<T>> : native_converter_base<functor<T>>
43+
{
44+
static int compute_score(lua_State *luaState, int index)
45+
{ return lua_type(luaState, index)==LUA_TFUNCTION ? 0 : -1; }
46+
47+
functor<T> from(lua_State *luaState, int index)
48+
{ return object(from_stack(luaState, index)); }
49+
50+
void to(lua_State *luaState, const functor<T> &func)
51+
{ func.push(luaState); }
52+
};
2453
}

0 commit comments

Comments
 (0)