From f4f3bffe2f27bb78b33d359d77aca135a5ae62f8 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 10 Dec 2016 01:19:23 -0500 Subject: [PATCH] Oh boy, more simplicity functions...! --- sol/coroutine.hpp | 2 ++ sol/function.hpp | 2 ++ sol/protected_function.hpp | 2 ++ sol/table_core.hpp | 2 ++ sol/thread.hpp | 2 ++ sol/userdata.hpp | 4 ++++ test_storage.cpp | 2 +- 7 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sol/coroutine.hpp b/sol/coroutine.hpp index 667f6529..17294aa5 100644 --- a/sol/coroutine.hpp +++ b/sol/coroutine.hpp @@ -80,6 +80,8 @@ namespace sol { coroutine(lua_nil_t r) : reference(r) {} coroutine(const stack_reference& r) noexcept : coroutine(r.lua_state(), r.stack_index()) {} coroutine(stack_reference&& r) noexcept : coroutine(r.lua_state(), r.stack_index()) {} + template >>, meta::neg>> = meta::enabler> + coroutine(lua_State* L, T&& r) : coroutine(L, sol::ref_index(r.registry_index())) {} coroutine(lua_State* L, int index = -1) : reference(L, index) { #ifdef SOL_CHECK_ARGUMENTS stack::check(L, index, type_panic); diff --git a/sol/function.hpp b/sol/function.hpp index 2d8c20b3..cd04f8de 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -81,6 +81,8 @@ namespace sol { basic_function& operator=(basic_function&&) = default; basic_function(const stack_reference& r) : basic_function(r.lua_state(), r.stack_index()) {} basic_function(stack_reference&& r) : basic_function(r.lua_state(), r.stack_index()) {} + template >>, meta::neg>> = meta::enabler> + basic_function(lua_State* L, T&& r) : basic_function(L, sol::ref_index(r.registry_index())) {} basic_function(lua_State* L, int index = -1) : base_t(L, index) { #ifdef SOL_CHECK_ARGUMENTS stack::check(L, index, type_panic); diff --git a/sol/protected_function.hpp b/sol/protected_function.hpp index 7abe599a..0f188a1a 100644 --- a/sol/protected_function.hpp +++ b/sol/protected_function.hpp @@ -161,6 +161,8 @@ namespace sol { basic_protected_function(proxy_base&& p, reference eh = get_default_handler()) : basic_protected_function(p.operator basic_function(), std::move(eh)) {} template basic_protected_function(const proxy_base& p, reference eh = get_default_handler()) : basic_protected_function(static_cast>(p), std::move(eh)) {} + template >>, meta::neg>> = meta::enabler> + basic_protected_function(lua_State* L, T&& r, reference eh) : basic_protected_function(L, sol::ref_index(r.registry_index()), std::move(eh)) {} basic_protected_function(lua_State* L, int index = -1, reference eh = get_default_handler()) : base_t(L, index), error_handler(std::move(eh)) { #ifdef SOL_CHECK_ARGUMENTS stack::check(L, index, type_panic); diff --git a/sol/table_core.hpp b/sol/table_core.hpp index 3a37097e..8004ebd2 100644 --- a/sol/table_core.hpp +++ b/sol/table_core.hpp @@ -174,6 +174,8 @@ namespace sol { basic_table_core& operator=(basic_table_core&&) = default; basic_table_core(const stack_reference& r) : basic_table_core(r.lua_state(), r.stack_index()) {} basic_table_core(stack_reference&& r) : basic_table_core(r.lua_state(), r.stack_index()) {} + template >>, meta::neg>> = meta::enabler> + basic_table_core(lua_State* L, T&& r) : basic_table_core(L, sol::ref_index(r.registry_index())) {} basic_table_core(lua_State* L, int index = -1) : base_t(L, index) { #ifdef SOL_CHECK_ARGUMENTS stack::check(L, index, type_panic); diff --git a/sol/thread.hpp b/sol/thread.hpp index c1395b31..92ef110d 100644 --- a/sol/thread.hpp +++ b/sol/thread.hpp @@ -94,6 +94,8 @@ namespace sol { thread(stack_reference&& r) : thread(r.lua_state(), r.stack_index()) {}; thread& operator=(const thread&) = default; thread& operator=(thread&&) = default; + template >>, meta::neg>> = meta::enabler> + thread(lua_State* L, T&& r) : thread(L, sol::ref_index(r.registry_index())) {} thread(lua_State* L, int index = -1) : reference(L, index) { #ifdef SOL_CHECK_ARGUMENTS type_assert(L, index, type::thread); diff --git a/sol/userdata.hpp b/sol/userdata.hpp index 6f451c98..382f89b1 100644 --- a/sol/userdata.hpp +++ b/sol/userdata.hpp @@ -44,6 +44,8 @@ namespace sol { basic_userdata& operator=(basic_userdata&&) = default; basic_userdata(const stack_reference& r) : basic_userdata(r.lua_state(), r.stack_index()) {} basic_userdata(stack_reference&& r) : basic_userdata(r.lua_state(), r.stack_index()) {} + template >>, meta::neg>> = meta::enabler> + basic_userdata(lua_State* L, T&& r) : basic_userdata(L, sol::ref_index(r.registry_index())) {} basic_userdata(lua_State* L, int index = -1) : base_t(L, index) { #ifdef SOL_CHECK_ARGUMENTS type_assert(L, index, type::userdata); @@ -76,6 +78,8 @@ namespace sol { basic_lightuserdata& operator=(basic_lightuserdata&&) = default; basic_lightuserdata(const stack_reference& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} basic_lightuserdata(stack_reference&& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} + template >>, meta::neg>> = meta::enabler> + basic_lightuserdata(lua_State* L, T&& r) : basic_lightuserdata(L, sol::ref_index(r.registry_index())) {} basic_lightuserdata(lua_State* L, int index = -1) : base_t(L, index) { #ifdef SOL_CHECK_ARGUMENTS type_assert(L, index, type::lightuserdata); diff --git a/test_storage.cpp b/test_storage.cpp index 7708e53c..2a93217a 100644 --- a/test_storage.cpp +++ b/test_storage.cpp @@ -13,7 +13,7 @@ end sol::state lua; sol::function f = lua["f"]; sol::reference r = lua["f"]; - sol::function regf(lua, sol::ref_index(f.registry_index())); + sol::function regf(lua, f); sol::reference regr(lua, sol::ref_index(f.registry_index())); bool isequal = f == r; REQUIRE(isequal);