mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Merge pull request #121 from chingjun/develop
Use nullptr when converting to std::function if value is nil
This commit is contained in:
commit
6cc8676bc7
|
@ -105,6 +105,9 @@ namespace sol {
|
||||||
|
|
||||||
template<typename... Args, typename... Ret>
|
template<typename... Args, typename... Ret>
|
||||||
static std::function<Signature> get_std_func(types<Ret...>, types<Args...>, lua_State* L, int index = -1) {
|
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);
|
sol::function f(L, index);
|
||||||
auto fx = [f, L, index](Args&&... args) -> meta::return_type_t<Ret...> {
|
auto fx = [f, L, index](Args&&... args) -> meta::return_type_t<Ret...> {
|
||||||
return f.call<Ret...>(std::forward<Args>(args)...);
|
return f.call<Ret...>(std::forward<Args>(args)...);
|
||||||
|
@ -114,6 +117,9 @@ namespace sol {
|
||||||
|
|
||||||
template<typename... FxArgs>
|
template<typename... FxArgs>
|
||||||
static std::function<Signature> get_std_func(types<void>, types<FxArgs...>, lua_State* L, int index = -1) {
|
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);
|
sol::function f(L, index);
|
||||||
auto fx = [f, L, index](FxArgs&&... args) -> void {
|
auto fx = [f, L, index](FxArgs&&... args) -> void {
|
||||||
f(std::forward<FxArgs>(args)...);
|
f(std::forward<FxArgs>(args)...);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user