From 14b1a3fe0c9dd31502e029838d21070ee8d0d07c Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 30 Jul 2014 00:19:58 -0700 Subject: [PATCH] Some missing support for reference-style (l-value reference and pointer) calls from lua. Fixed. --- sol/function_types.hpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/sol/function_types.hpp b/sol/function_types.hpp index d993be83..87ab95dc 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -280,6 +280,10 @@ struct functor_function : public base_function { virtual int operator()(lua_State* L) override { return (*this)(tuple_types(), args_type(), L); } + + virtual int operator()(lua_State* L, detail::ref_call_t) override { + return (*this)(tuple_types(), args_type(), L); + } }; template @@ -326,6 +330,10 @@ struct member_function : public base_function { virtual int operator()(lua_State* L) override { return (*this)(tuple_types(), args_type(), L); } + + virtual int operator()(lua_State* L, detail::ref_call_t) override { + return (*this)(tuple_types(), args_type(), L); + } }; template @@ -427,17 +435,7 @@ struct userdata_variable_function : public userdata_function_core template int fx_call (lua_State* L) { - type t = stack::get(L, 1); - switch(t) { - case type::table: - lua_getfield(L, 1, "sol.userdatavalue"); - this->fx.item = detail::get_ptr(stack::get(L, -1)); - lua_pop(L, 1); - break; - default: - this->fx.item = detail::get_ptr(stack::get(L, 1)); - break; - } + this->fx.item = detail::get_ptr(stack::get(L, 1)); if (this->fx.item == nullptr) throw error("userdata for member variable is null"); int argcount = lua_gettop(L); @@ -482,11 +480,17 @@ struct userdata_indexing_function : public userdata_function_core if (function != functions.end()) { if (function->second.second) { stack::push(L, function->second.first.get()); - stack::push(L, &base_function::userdata<0>::call, 1); + if (std::is_same::value) + stack::push(L, &base_function::userdata<0>::ref_call, 1); + else + stack::push(L, &base_function::userdata<0>::call, 1); return 1; } else { - return (*function->second.first)(L); + if (std::is_same::value) + return (*function->second.first)(L, detail::ref_call); + else + return (*function->second.first)(L); } } if (this->fx.invocation == nullptr) {