Skip to content

Commit

Permalink
Fix compatibility with Lua 5.4
Browse files Browse the repository at this point in the history
The couroutine result index is always 1, not dependent on the number of
results which is not available in < 5.4.
Errors during GC are shown as warnings in 5.4+
  • Loading branch information
Flamefire committed Jan 4, 2025
1 parent 698eab8 commit ef2f9cc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions include/kaguya/detail/lua_function_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ template <typename Derived> class LuaThreadImpl {
int nresult = 1;
int result = lua_resume(thread, state, argnum, &nresult);
except::checkErrorAndThrow(result, thread);
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1),
types::typetag<Result>());
return detail::FunctionResultProxy::ReturnValue(thread, result, 1, types::typetag<Result>());
}
template <class... Args> FunctionResults operator()(Args &&... args);
#else
Expand Down Expand Up @@ -197,8 +196,7 @@ template <typename Derived> class LuaThreadImpl {
int nresult = 1; \
int result = lua_resume(thread, state, argnum, &nresult); \
except::checkErrorAndThrow(result, thread); \
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1), \
types::typetag<Result>()); \
return detail::FunctionResultProxy::ReturnValue(thread, result, 1, types::typetag<Result>()); \
}

KAGUYA_RESUME_DEF(0)
Expand Down
2 changes: 1 addition & 1 deletion test/test_06_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ KAGUYA_TEST_FUNCTION_DEF(this_typemismatch_error_test)(kaguya::State &state) {
}
}

#if LUA_VERSION_NUM >= 502
#if LUA_VERSION_NUM >= 502 && LUA_VERSION_NUM < 504
KAGUYA_TEST_FUNCTION_DEF(gc_error_throw_test)(kaguya::State &) {
bool catch_except = false;
try {
Expand Down

0 comments on commit ef2f9cc

Please sign in to comment.