Skip to content

Commit 54e6910

Browse files
authored
Merge branch 'satoren:main' into patch-1
2 parents ee350d5 + 2f20d96 commit 54e6910

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

include/kaguya/compatibility.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
namespace kaguya {
1010
// for lua version compatibility
1111
namespace compat {
12+
#if LUA_VERSION_NUM >= 504
13+
#elif LUA_VERSION_NUM < 502
14+
inline int lua_resume(lua_State *L, lua_State *from, int nargs, int* nresults) {
15+
KAGUYA_UNUSED(from);
16+
*nresults = 1;
17+
return ::lua_resume(L, nargs);
18+
}
19+
#else
20+
inline int lua_resume(lua_State *L, lua_State *from, int nargs, int* nresults) {
21+
*nresults = 1;
22+
return ::lua_resume(L, from, nargs);
23+
}
24+
#endif
1225
#if LUA_VERSION_NUM >= 503
1326
inline int lua_rawgetp_rtype(lua_State *L, int idx, const void *ptr) {
1427
return lua_rawgetp(L, idx, ptr);
@@ -54,10 +67,6 @@ inline size_t lua_rawlen(lua_State *L, int index) {
5467
return lua_objlen(L, index);
5568
}
5669

57-
inline int lua_resume(lua_State *L, lua_State *from, int nargs) {
58-
KAGUYA_UNUSED(from);
59-
return ::lua_resume(L, nargs);
60-
}
6170
inline int lua_absindex(lua_State *L, int idx) {
6271
return (idx > 0 || (idx <= LUA_REGISTRYINDEX)) ? idx
6372
: lua_gettop(L) + 1 + idx;

include/kaguya/detail/lua_function_def.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,14 @@ template <typename Derived> class LuaThreadImpl {
162162
if (argnum < 0) {
163163
argnum = 0;
164164
}
165-
int result = lua_resume(thread, state, argnum);
165+
int nresult = 1;
166+
int result = lua_resume(thread, state, argnum, &nresult);
166167
except::checkErrorAndThrow(result, thread);
167-
return detail::FunctionResultProxy::ReturnValue(thread, result, 1,
168+
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1),
168169
types::typetag<Result>());
169170
}
170171
template <class... Args> FunctionResults operator()(Args &&... args);
171172
#else
172-
173173
#define KAGUYA_RESUME_DEF(N) \
174174
template <class Result KAGUYA_PP_TEMPLATE_DEF_REPEAT_CONCAT(N)> \
175175
Result resume(KAGUYA_PP_ARG_CR_DEF_REPEAT(N)) { \
@@ -194,9 +194,10 @@ template <typename Derived> class LuaThreadImpl {
194194
if (argnum < 0) { \
195195
argnum = 0; \
196196
} \
197-
int result = lua_resume(thread, state, argnum); \
197+
int nresult = 1; \
198+
int result = lua_resume(thread, state, argnum, &nresult); \
198199
except::checkErrorAndThrow(result, thread); \
199-
return detail::FunctionResultProxy::ReturnValue(thread, result, 1, \
200+
return detail::FunctionResultProxy::ReturnValue(thread, result, nresult - (lua_gettop(state) + 1), \
200201
types::typetag<Result>()); \
201202
}
202203

test/test_03_function.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ int cfunction(lua_State *L) {
235235

236236
int coroutinefn(lua_State *cor) {
237237
using namespace kaguya;
238-
lua_resume(cor, 0, 0);
238+
int nresult = 0;
239+
lua_resume(cor, 0, 0, &nresult);
239240
return static_cast<int>(lua_tointeger(cor, 1));
240241
}
241242

test/test_05_lua_ref.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ void ignore_error_fun(int status, const char *message) {
1313
KAGUYA_TEST_FUNCTION_DEF(access)(kaguya::State &state) {
1414
kaguya::LuaRef ref(state.state(), "abc");
1515
TEST_EQUAL(ref.get<std::string>(), "abc");
16-
ref = ref;
1716

1817
state("abc={d =1,e=3,f=64,g='sss'}");
1918
kaguya::LuaRef abctable = state["abc"];

test/test_09_utility.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ KAGUYA_TEST_FUNCTION_DEF(lua_resume_test)(kaguya::State &s) {
4848
lua_pushnumber(co, 2);
4949
lua_pushnumber(co, 3);
5050

51-
lua_resume(co, s.state(), 2);
51+
int nres;
52+
lua_resume(co, s.state(), 2, &nres);
5253

5354
TEST_EQUAL(s["v"][1], 2);
5455
TEST_EQUAL(s["v"][2], 3);

test/test_12_push_any.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ KAGUYA_TEST_FUNCTION_DEF(push_any_type)(kaguya::State &state) {
2121
AnyDataPusher a("d");
2222
AnyDataPusher b(4);
2323
a = b;
24-
a = a;
2524
AnyDataPusher c;
2625
TEST_COMPARE_EQ(state.newRef(a), 4);
2726
TEST_COMPARE_EQ(state.newRef(b), 4);

0 commit comments

Comments
 (0)