From 0faacb5d2ca5735f5272c2e3429a3f4b8af972f4 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 20 Jun 2016 07:03:44 -0400 Subject: [PATCH] Slight refactoring of implementation. Also, stray #endif due to not being recognized by include guard regex -- the formula must be kept...! (TODO: transition sol2 to include guards...?) --- sol/bind_traits.hpp | 2 +- sol/function.hpp | 10 ++++------ sol/stack_check.hpp | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) 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) {