Skip to content

Commit

Permalink
fix: build error on lua 5.4.x (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
satoren authored Jan 4, 2025
1 parent 9d77cad commit 2f20d96
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
17 changes: 13 additions & 4 deletions include/kaguya/compatibility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
namespace kaguya {
// for lua version compatibility
namespace compat {
#if LUA_VERSION_NUM >= 504
#elif LUA_VERSION_NUM < 502
inline int lua_resume(lua_State *L, lua_State *from, int nargs, int* nresults) {
KAGUYA_UNUSED(from);
*nresults = 1;
return ::lua_resume(L, nargs);
}
#else
inline int lua_resume(lua_State *L, lua_State *from, int nargs, int* nresults) {
*nresults = 1;
return ::lua_resume(L, from, nargs);
}
#endif
#if LUA_VERSION_NUM >= 503
inline int lua_rawgetp_rtype(lua_State *L, int idx, const void *ptr) {
return lua_rawgetp(L, idx, ptr);
Expand Down Expand Up @@ -54,10 +67,6 @@ inline size_t lua_rawlen(lua_State *L, int index) {
return lua_objlen(L, index);
}

inline int lua_resume(lua_State *L, lua_State *from, int nargs) {
KAGUYA_UNUSED(from);
return ::lua_resume(L, nargs);
}
inline int lua_absindex(lua_State *L, int idx) {
return (idx > 0 || (idx <= LUA_REGISTRYINDEX)) ? idx
: lua_gettop(L) + 1 + idx;
Expand Down
11 changes: 6 additions & 5 deletions include/kaguya/detail/lua_function_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ template <typename Derived> class LuaThreadImpl {
if (argnum < 0) {
argnum = 0;
}
int result = lua_resume(thread, state, argnum);
int nresult = 1;
int result = lua_resume(thread, state, argnum, &nresult);
except::checkErrorAndThrow(result, thread);
return detail::FunctionResultProxy::ReturnValue(thread, result, 1,
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1),
types::typetag<Result>());
}
template <class... Args> FunctionResults operator()(Args &&... args);
#else

#define KAGUYA_RESUME_DEF(N) \
template <class Result KAGUYA_PP_TEMPLATE_DEF_REPEAT_CONCAT(N)> \
Result resume(KAGUYA_PP_ARG_CR_DEF_REPEAT(N)) { \
Expand All @@ -194,9 +194,10 @@ template <typename Derived> class LuaThreadImpl {
if (argnum < 0) { \
argnum = 0; \
} \
int result = lua_resume(thread, state, argnum); \
int nresult = 1; \
int result = lua_resume(thread, state, argnum, &nresult); \
except::checkErrorAndThrow(result, thread); \
return detail::FunctionResultProxy::ReturnValue(thread, result, 1, \
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1), \
types::typetag<Result>()); \
}

Expand Down
3 changes: 2 additions & 1 deletion test/test_03_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ int cfunction(lua_State *L) {

int coroutinefn(lua_State *cor) {
using namespace kaguya;
lua_resume(cor, 0, 0);
int nresult = 0;
lua_resume(cor, 0, 0, &nresult);
return static_cast<int>(lua_tointeger(cor, 1));
}

Expand Down
1 change: 0 additions & 1 deletion test/test_05_lua_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ void ignore_error_fun(int status, const char *message) {
KAGUYA_TEST_FUNCTION_DEF(access)(kaguya::State &state) {
kaguya::LuaRef ref(state.state(), "abc");
TEST_EQUAL(ref.get<std::string>(), "abc");
ref = ref;

state("abc={d =1,e=3,f=64,g='sss'}");
kaguya::LuaRef abctable = state["abc"];
Expand Down
3 changes: 2 additions & 1 deletion test/test_09_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ KAGUYA_TEST_FUNCTION_DEF(lua_resume_test)(kaguya::State &s) {
lua_pushnumber(co, 2);
lua_pushnumber(co, 3);

lua_resume(co, s.state(), 2);
int nres;
lua_resume(co, s.state(), 2, &nres);

TEST_EQUAL(s["v"][1], 2);
TEST_EQUAL(s["v"][2], 3);
Expand Down
1 change: 0 additions & 1 deletion test/test_12_push_any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ KAGUYA_TEST_FUNCTION_DEF(push_any_type)(kaguya::State &state) {
AnyDataPusher a("d");
AnyDataPusher b(4);
a = b;
a = a;
AnyDataPusher c;
TEST_COMPARE_EQ(state.newRef(a), 4);
TEST_COMPARE_EQ(state.newRef(b), 4);
Expand Down

0 comments on commit 2f20d96

Please sign in to comment.