Skip to content

Commit 1678632

Browse files
author
nitrocaster
committed
Allow nil functor call.
1 parent 5376a2f commit 1678632

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/xrScriptEngine/Functor.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ template<typename T>
4242
struct default_converter<functor<T>> : native_converter_base<functor<T>>
4343
{
4444
static int compute_score(lua_State *luaState, int index)
45-
{ return lua_type(luaState, index)==LUA_TFUNCTION ? 0 : -1; }
45+
{ return lua_isfunction(luaState, index) || lua_isnil(luaState, index) ? 0 : -1; }
4646

4747
functor<T> from(lua_State *luaState, int index)
48-
{ return object(from_stack(luaState, index)); }
48+
{
49+
if (lua_isnil(luaState, index))
50+
return functor<T>();
51+
return object(from_stack(luaState, index));
52+
}
4953

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

0 commit comments

Comments
 (0)