Skip to content

Commit

Permalink
Add default_converter and type_to_string specs for functor.
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrocaster committed Nov 25, 2015
1 parent fe7bc5f commit 12c051a
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/xrScriptEngine/Functor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "xrScriptEngine/xrScriptEngine.hpp"
#include <type_traits>
#include <luabind/detail/format_signature.hpp>

namespace luabind
{
Expand All @@ -21,4 +22,32 @@ template<>
template<typename... Args>
void functor<void>::operator()(Args &&...args) const
{ call_function<void>(*static_cast<const adl::object *>(this), std::forward<Args>(args)...); }

namespace detail
{
template<typename T>
struct type_to_string<functor<T>>
{
static void get(lua_State *L)
{
lua_pushstring(L, "function<");
type_to_string<T>::get(L);
lua_pushstring(L, ">");
lua_concat(L, 3);
}
};
}

template<typename T>
struct default_converter<functor<T>> : native_converter_base<functor<T>>
{
static int compute_score(lua_State *luaState, int index)
{ return lua_type(luaState, index)==LUA_TFUNCTION ? 0 : -1; }

functor<T> from(lua_State *luaState, int index)
{ return object(from_stack(luaState, index)); }

void to(lua_State *luaState, const functor<T> &func)
{ func.push(luaState); }
};
}

0 comments on commit 12c051a

Please sign in to comment.