From 4ac35aa8f47589ce2a074f1bf784a30edd268445 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 2 Oct 2016 13:37:52 -0400 Subject: [PATCH] sometimes, I have a dumb. Othertimes, the lua docs are sneaky and have subtle maybe-behaviors when other parts of their API never do. Sneaky, sneaky API... --- sol/object.hpp | 8 ++++++++ sol/stack_check.hpp | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sol/object.hpp b/sol/object.hpp index 460faa31..5a038a3a 100644 --- a/sol/object.hpp +++ b/sol/object.hpp @@ -95,6 +95,14 @@ namespace sol { basic_object& operator=(base_t&& b) { base_t::operator=(std::move(b)); return *this; } basic_object(const stack_reference& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {} basic_object(stack_reference&& r) noexcept : basic_object(r.lua_state(), r.stack_index()) {} + template + basic_object(const proxy_base& r) noexcept : basic_object(r.operator basic_object()) {} + template + basic_object(proxy_base&& r) noexcept : basic_object(r.operator basic_object()) {} + template + basic_object& operator=(const proxy_base& r) { this->operator=(r.operator basic_object()); return *this; } + template + basic_object& operator=(proxy_base&& r) { this->operator=(r.operator basic_object()); return *this; } basic_object(lua_State* L, int index = -1) noexcept : base_t(L, index) {} template basic_object(lua_State* L, in_place_type_t, Args&&... args) noexcept : basic_object(std::integral_constant::value>(), L, -stack::push(L, std::forward(args)...)) {} diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index 03a71d38..bf9faa1e 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -199,7 +199,11 @@ namespace sol { } // Do advanced check for call-style userdata? static const auto& callkey = name_of(meta_function::call); - lua_getmetatable(L, index); + if (lua_getmetatable(L, index) == 0) { + // No metatable, no __call key possible + handler(L, index, type::function, t); + return false; + } if (lua_isnoneornil(L, -1)) { lua_pop(L, 1); handler(L, index, type::function, t);