mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
🛠 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:
parent
ba7aff015d
commit
839f2a1dce
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user