Merge pull request #121 from chingjun/develop

Use nullptr when converting to std::function if value is nil
This commit is contained in:
The Phantom Derpstorm 2016-06-20 06:44:43 -04:00 committed by GitHub
commit 6cc8676bc7

View File

@ -105,6 +105,9 @@ namespace sol {
template<typename... Args, typename... Ret>
static std::function<Signature> get_std_func(types<Ret...>, types<Args...>, 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<Ret...> {
return f.call<Ret...>(std::forward<Args>(args)...);
@ -114,6 +117,9 @@ namespace sol {
template<typename... FxArgs>
static std::function<Signature> get_std_func(types<void>, types<FxArgs...>, 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<FxArgs>(args)...);