diff --git a/sol/stack.hpp b/sol/stack.hpp index 8d2648c9..fb3b1f3f 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -85,6 +85,12 @@ namespace sol { } } // stack_detail + template + int set_ref(lua_State* L, T&& arg, int tableindex = -2) { + push(L, std::forward(arg)); + return luaL_ref(L, tableindex); + } + inline void remove(lua_State* L, int index, int count) { if (count < 1) return; diff --git a/sol/table_core.hpp b/sol/table_core.hpp index b325227b..fd7a3c30 100644 --- a/sol/table_core.hpp +++ b/sol/table_core.hpp @@ -334,11 +334,9 @@ namespace sol { template basic_table_core& add(Args&&... args) { auto pp = stack::push_pop(*this); - auto action = [&](auto&& arg) { - stack::push(base_t::lua_state(), std::forward(arg)); - luaL_ref(base_t::lua_state(), -2); + (void)detail::swallow{0, + (stack::set_ref(base_t::lua_state(), std::forward(args)), 0)... }; - (void)detail::swallow{0, (action(std::forward(args)), 0)...}; return *this; }