Skip to content

Commit 06aff62

Browse files
committed
userdata支持__pairs
1 parent 720f190 commit 06aff62

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

extension/script/backend/worker/variables.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,9 +934,9 @@ local function extandUserdata(varRef)
934934
end
935935
end
936936

937-
local members = {}
938937
local loct = rdebug.userdata_pairs(u)
939938
if loct then
939+
local members = {}
940940
for i = 1, #loct, 3 do
941941
local key, value, valueref = loct[i], loct[i + 1], loct[i + 2]
942942
local key_type = rdebug.type(key)
@@ -954,9 +954,8 @@ local function extandUserdata(varRef)
954954
end
955955
end
956956
table.sort(members, function(a, b) return a.name < b.name end)
957-
table.move(members, 1, #members, #vars + 1)
957+
table.move(members, 1, #members, #vars + 1, vars)
958958
end
959-
960959
return vars
961960
end
962961

src/luadebug/rdebug_visitor.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,18 @@ namespace luadebug::visitor {
275275
if (!copy_from_dbg(L, hL, area, 1, LUADBG_TUSERDATA)) {
276276
return 0;
277277
}
278-
if (lua_getmetatable(hL, -1) == 0) {
278+
if (!lua_getmetatable(hL, -1)) {
279279
lua_pop(hL, 1);
280280
return 0;
281281
}
282282
lua_getfield(hL, -1, "__pairs");
283-
if (LUA_TFUNCTION == lua_type(hL, -1)) {
283+
if (LUA_TFUNCTION != lua_type(hL, -1)) {
284284
lua_pop(hL, 3);
285285
return 0;
286286
}
287287
lua_remove(hL, -2);
288288
lua_insert(hL, -2);
289-
if (!debug_pcall(hL, 1, 3, 0)) {
289+
if (debug_pcall(hL, 1, 3, 0)) {
290290
lua_pop(hL, 1);
291291
return 0;
292292
}
@@ -300,7 +300,7 @@ namespace luadebug::visitor {
300300
lua_pushvalue(hL, -3);
301301
lua_remove(hL, -4);
302302
// next, t, next, t, k
303-
if (!debug_pcall(hL, 2, 2, 0)) {
303+
if (debug_pcall(hL, 2, 2, 0)) {
304304
lua_pop(hL, 3);
305305
return 0;
306306
}
@@ -309,27 +309,27 @@ namespace luadebug::visitor {
309309
lua_pop(hL, 4);
310310
return 1;
311311
}
312-
if (copy_to_dbg(hL, L) == LUA_TNONE) {
312+
if (copy_to_dbg(hL, L, -2) == LUA_TNONE) {
313313
refvalue::create(L, 1, refvalue::USERDATA_KEY { index });
314314
}
315315
luadbg_rawseti(L, -2, ++n);
316-
lua_pop(hL, 1);
317316

318317
if (getref) {
319318
refvalue::create(L, 1, refvalue::USERDATA_VAL { index });
320-
if (copy_to_dbg(hL, L) == LUA_TNONE) {
319+
if (copy_to_dbg(hL, L, -1) == LUA_TNONE) {
321320
luadbg_pushvalue(L, -1);
322321
}
323322
luadbg_rawseti(L, -3, ++n);
324323
} else {
325-
if (copy_to_dbg(hL, L) == LUA_TNONE) {
324+
if (copy_to_dbg(hL, L, -1) == LUA_TNONE) {
326325
refvalue::create(L, 1, refvalue::USERDATA_VAL { index });
327326
}
328327
}
329-
++index;
330328
luadbg_rawseti(L, -2, ++n);
329+
lua_pop(hL, 1);
330+
331+
++index;
331332
}
332-
return 1;
333333
}
334334

335335
template <bool getref = true>

src/luadebug/util/refvalue.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,18 @@ namespace luadebug::refvalue {
237237
lua_pop(hL, 1);
238238
return LUA_TNONE;
239239
}
240-
if (lua_getmetatable(hL, -1) == 0) {
240+
if (!lua_getmetatable(hL, -1)) {
241241
lua_pop(hL, 1);
242242
return LUA_TNONE;
243243
}
244244
lua_getfield(hL, -1, "__pairs");
245-
if (LUA_TFUNCTION == lua_type(hL, -1)) {
245+
if (LUA_TFUNCTION != lua_type(hL, -1)) {
246246
lua_pop(hL, 3);
247247
return LUA_TNONE;
248248
}
249249
lua_remove(hL, -2);
250250
lua_insert(hL, -2);
251-
if (!debug_pcall(hL, 1, 3, 0)) {
251+
if (debug_pcall(hL, 1, 3, 0)) {
252252
lua_pop(hL, 1);
253253
return LUA_TNONE;
254254
}
@@ -259,7 +259,7 @@ namespace luadebug::refvalue {
259259
lua_pushvalue(hL, -3);
260260
lua_remove(hL, -4);
261261
// next, t, next, t, k
262-
if (!debug_pcall(hL, 2, 2, 0)) {
262+
if (debug_pcall(hL, 2, 2, 0)) {
263263
lua_pop(hL, 3);
264264
return LUA_TNONE;
265265
}
@@ -287,18 +287,18 @@ namespace luadebug::refvalue {
287287
lua_pop(hL, 1);
288288
return LUA_TNONE;
289289
}
290-
if (lua_getmetatable(hL, -1) == 0) {
290+
if (!lua_getmetatable(hL, -1)) {
291291
lua_pop(hL, 1);
292292
return LUA_TNONE;
293293
}
294294
lua_getfield(hL, -1, "__pairs");
295-
if (LUA_TFUNCTION == lua_type(hL, -1)) {
295+
if (LUA_TFUNCTION != lua_type(hL, -1)) {
296296
lua_pop(hL, 3);
297297
return LUA_TNONE;
298298
}
299299
lua_remove(hL, -2);
300300
lua_insert(hL, -2);
301-
if (!debug_pcall(hL, 1, 3, 0)) {
301+
if (debug_pcall(hL, 1, 3, 0)) {
302302
lua_pop(hL, 1);
303303
return LUA_TNONE;
304304
}
@@ -309,7 +309,7 @@ namespace luadebug::refvalue {
309309
lua_pushvalue(hL, -3);
310310
lua_remove(hL, -4);
311311
// next, t, next, t, k
312-
if (!debug_pcall(hL, 2, 2, 0)) {
312+
if (debug_pcall(hL, 2, 2, 0)) {
313313
lua_pop(hL, 3);
314314
return LUA_TNONE;
315315
}

0 commit comments

Comments
 (0)