🛠 Fix up example to use cpp_object properly as the name, and other checks.

— Addresses #1454
— Remove zero-based check for certain versioning macros for Lua (need others?)
This commit is contained in:
ThePhD 2023-07-18 13:45:11 -04:00
parent ba7aff015d
commit 839f2a1dce
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA
2 changed files with 16 additions and 9 deletions

View File

@ -24,20 +24,27 @@ int main(int, char*[]) {
}; };
lua.new_usertype<cpp_object>( lua.new_usertype<cpp_object>(
"test", "value", &cpp_object::value); "cpp_object", "value", &cpp_object::value);
lua.new_usertype<test>("test", "func", &test::func); lua.new_usertype<test>("test", "func", &test::func);
lua.script( lua.script(
"function test:lua_func(obj) print('lua_func', " "function test:lua_func(obj) print('lua_func', "
"obj.value) end"); "obj.value) return obj.value end");
lua["obj"] = test {}; lua["obj"] = test {};
cpp_object cppobj; cpp_object cppobj;
lua["obj"]["func"](lua["obj"], cppobj); int obj_func_call = lua["obj"]["func"](lua["obj"], cppobj);
lua["obj"]["lua_func"](lua["obj"], cppobj); int obj_lua_func_call
= lua["obj"]["lua_func"](lua["obj"], cppobj);
lua["test"]["func"](lua["obj"], cppobj); int test_func_call = lua["test"]["func"](lua["obj"], cppobj);
lua["test"]["lua_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 // crashes
// lua["obj"]["func"](cppobj); // lua["obj"]["func"](cppobj);

View File

@ -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) // 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) #if (SOL_LUA_VERSION_I_ == 502)
#define SOL_LUA_BIT32_LIB_I_ SOL_ON #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 #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 #define SOL_LUA_BIT32_LIB_I_ SOL_ON
#else #else
#define SOL_LUA_BIT32_LIB_I_ SOL_DEFAULT_OFF #define SOL_LUA_BIT32_LIB_I_ SOL_DEFAULT_OFF