From 6529c95efc09c24a48f29ddf15753a0e8fc5f358 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 4 Mar 2024 17:22:30 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20Fix=20up=20example=20to=20use=20?= =?UTF-8?q?cpp=5Fobject=20properly=20as=20the=20name,=20and=20other=20chec?= =?UTF-8?q?ks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — Addresses #1454 — Remove zero-based check for certain versioning macros for Lua (need others?) --- examples/source/usertype_call_from_c++.cpp | 21 ++++++++++++++------- include/sol/compatibility/lua_version.hpp | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/examples/source/usertype_call_from_c++.cpp b/examples/source/usertype_call_from_c++.cpp index 55d790c0..8ef83e98 100644 --- a/examples/source/usertype_call_from_c++.cpp +++ b/examples/source/usertype_call_from_c++.cpp @@ -24,20 +24,27 @@ int main(int, char*[]) { }; lua.new_usertype( - "test", "value", &cpp_object::value); + "cpp_object", "value", &cpp_object::value); lua.new_usertype("test", "func", &test::func); lua.script( "function test:lua_func(obj) print('lua_func', " - "obj.value) end"); + "obj.value) return obj.value end"); lua["obj"] = test {}; cpp_object cppobj; - lua["obj"]["func"](lua["obj"], cppobj); - lua["obj"]["lua_func"](lua["obj"], cppobj); + int obj_func_call = lua["obj"]["func"](lua["obj"], cppobj); + int obj_lua_func_call + = lua["obj"]["lua_func"](lua["obj"], cppobj); - lua["test"]["func"](lua["obj"], cppobj); - lua["test"]["lua_func"](lua["obj"], cppobj); + int test_func_call = lua["test"]["func"](lua["obj"], cppobj); + int test_lua_func_call + = lua["test"]["lua_func"](lua["obj"], cppobj); + + SOL_ASSERT(obj_func_call == 5); + SOL_ASSERT(obj_lua_func_call == 5); + SOL_ASSERT(test_func_call == 10); + SOL_ASSERT(test_lua_func_call == 5); // crashes // lua["obj"]["func"](cppobj); @@ -48,4 +55,4 @@ int main(int, char*[]) { // lua["test"]["lua_func"](cppobj); return 0; -} \ No newline at end of file +} diff --git a/include/sol/compatibility/lua_version.hpp b/include/sol/compatibility/lua_version.hpp index 8d2b4225..e97999e8 100644 --- a/include/sol/compatibility/lua_version.hpp +++ b/include/sol/compatibility/lua_version.hpp @@ -194,9 +194,9 @@ // Lua 5.2, or other versions of Lua with the compat flag, or Lua that is not 5.2 with the specific define (5.4.1 either removed it entirely or broke it) #if (SOL_LUA_VERSION_I_ == 502) #define SOL_LUA_BIT32_LIB_I_ SOL_ON - #elif (defined(LUA_COMPAT_BITLIB) && (LUA_COMPAT_BITLIB != 0)) + #elif defined(LUA_COMPAT_BITLIB) #define SOL_LUA_BIT32_LIB_I_ SOL_ON - #elif (SOL_LUA_VERSION_I_ < 504 && (defined(LUA_COMPAT_5_2) && (LUA_COMPAT_5_2 != 0))) + #elif (SOL_LUA_VERSION_I_ < 504 && defined(LUA_COMPAT_5_2)) #define SOL_LUA_BIT32_LIB_I_ SOL_ON #else #define SOL_LUA_BIT32_LIB_I_ SOL_DEFAULT_OFF