diff --git a/sol/bind_traits.hpp b/sol/bind_traits.hpp index 5b18b403..1549d4f0 100644 --- a/sol/bind_traits.hpp +++ b/sol/bind_traits.hpp @@ -239,4 +239,4 @@ namespace sol { } // meta } // sol -#endif // SOL_BIND_TRAITS +#endif // SOL_BIND_TRAITS_HPP diff --git a/sol/function.hpp b/sol/function.hpp index 38baeefb..6e26d455 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -105,9 +105,6 @@ 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)...); @@ -117,9 +114,6 @@ 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)...); @@ -133,6 +127,10 @@ namespace sol { } static std::function get(lua_State* L, int index) { + type t = type_of(L, index); + if (t == type::none || t == type::nil) { + return nullptr; + } return get_std_func(return_types(), args_lists(), L, index); } }; diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index 05c373bf..fd920fc4 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -196,7 +196,8 @@ namespace sol { template static bool check(lua_State* L, int index, Handler&& handler) { type t = type_of(L, index); - if (t == type::function) { + if (t == type::nil || t == type::none || t == type::function) { + // allow for nil to be returned return true; } if (t != type::userdata && t != type::table) {