From b6ba214f43b374b72067c56a30a968cfd991553e Mon Sep 17 00:00:00 2001 From: Lau Ching Jun Date: Mon, 20 Jun 2016 11:53:51 +0800 Subject: [PATCH] Use nullptr when converting to std::function if value is nil --- sol/function.hpp | 6 ++++++ 1 file changed, 6 insertions(+) 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)...);