From 8eb10388c183b430e9ce7790f0e478b4c799f644 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Fri, 10 Jun 2016 23:05:25 -0400 Subject: [PATCH] directly insert lua_cfunctions --- sol/usertype_metatable.hpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sol/usertype_metatable.hpp b/sol/usertype_metatable.hpp index f0b1f1ec..fb2bcb45 100644 --- a/sol/usertype_metatable.hpp +++ b/sol/usertype_metatable.hpp @@ -67,9 +67,9 @@ namespace sol { return string_detail::string_shim(detail::base_class_cast_key()); } - template - inline luaL_Reg make_reg(N&& n, F&& f) { - luaL_Reg l{ make_shim(std::forward(n)).c_str(), std::forward(f) }; + template + inline luaL_Reg make_reg(N&& n, lua_CFunction f) { + luaL_Reg l{ make_shim(std::forward(n)).c_str(), f }; return l; } @@ -106,6 +106,16 @@ namespace sol { bool mustindex; bool secondarymeta; + template + static inline lua_CFunction make_func(lua_CFunction& f) { + return f; + } + + template + static inline lua_CFunction make_func(F&&) { + return call; + } + template static bool contains_variable(std::index_sequence) { typedef meta::any...> has_variables; @@ -159,7 +169,7 @@ namespace sol { } template , base_classes_tag, call_construction>::value>> - int make_regs(regs_t& l, int index, N&& n, F&&, Args&&... args) { + int make_regs(regs_t& l, int index, N&& n, F&& f, Args&&... args) { string_detail::string_shim shimname = usertype_detail::make_shim(n); // Returnable scope // That would be a neat keyword for C++ @@ -174,7 +184,7 @@ namespace sol { mustindex = true; return; } - l[index] = usertype_detail::make_reg(std::forward(n), call); + l[index] = usertype_detail::make_reg(std::forward(n), make_func(std::forward(f))); ++index; }(); return make_regs(l, index, std::forward(args)...);