diff --git a/sol/function.hpp b/sol/function.hpp index ea6aa372..38baeefb 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -105,6 +105,9 @@ namespace sol { template static std::function get_std_func(types, types, lua_State* L, int index = -1) { + if (lua_isnil(L, index) || lua_isnone(L, index)) { + return nullptr; + } sol::function f(L, index); auto fx = [f, L, index](Args&&... args) -> meta::return_type_t { return f.call(std::forward(args)...); @@ -114,6 +117,9 @@ namespace sol { template static std::function get_std_func(types, types, lua_State* L, int index = -1) { + if (lua_isnil(L, index) || lua_isnone(L, index)) { + return nullptr; + } sol::function f(L, index); auto fx = [f, L, index](FxArgs&&... args) -> void { f(std::forward(args)...);