Skip to content

Commit

Permalink
🛠 Fix up example to use cpp_object properly as the name, and other ch…
Browse files Browse the repository at this point in the history
…ecks.

— Addresses #1454
— Remove zero-based check for certain versioning macros for Lua (need others?)
  • Loading branch information
ThePhD committed Jul 18, 2023
1 parent ba7aff0 commit 839f2a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions examples/source/usertype_call_from_c++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ int main(int, char*[]) {
};

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.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);
Expand All @@ -48,4 +55,4 @@ int main(int, char*[]) {
// lua["test"]["lua_func"](cppobj);

return 0;
}
}
4 changes: 2 additions & 2 deletions include/sol/compatibility/lua_version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 839f2a1

Please sign in to comment.