Skip to content

Commit 62eeed1

Browse files
committed
fix invalid key to 'next'
1 parent 8510029 commit 62eeed1

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

emmy_debugger/src/debugger/emmy_debugger.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,33 @@ void Debugger::GetVariable(lua_State *L, Idx<Variable> variable, int index, int
447447
auto v = variable.GetArena()->Alloc();
448448
const auto t = lua_type(L, -2);
449449
v->nameType = t;
450-
if (t == LUA_TSTRING || t == LUA_TNUMBER || t == LUA_TBOOLEAN) {
451-
lua_pushvalue(L, -2);// avoid error: "invalid key to 'next'" ???
452-
v->name = lua_tostring(L, -1);
453-
lua_pop(L, 1);
454-
} else {
455-
v->name = ToPointer(L, -2);
456-
}
450+
switch (t) {
451+
case LUA_TSTRING:
452+
{
453+
v->name = lua_tostring(L, -2);
454+
break;
455+
}
456+
case LUA_TNUMBER:
457+
{
458+
auto number = lua_tonumber(L, -2);
459+
if (static_cast<long long>(number) == number) {
460+
v->name = std::to_string(static_cast<long long>(number));
461+
} else {
462+
v->name = std::to_string(number);
463+
}
464+
break;
465+
}
466+
case LUA_TBOOLEAN:
467+
{
468+
v->name = lua_toboolean(L, -2) ? "true" : "false";
469+
break;
470+
}
471+
default: {
472+
v->name = ToPointer(L, -2);
473+
break;
474+
}
475+
}
476+
457477
GetVariable(L, v, -1, depth - 1);
458478
variable->children.push_back(v);
459479
}

0 commit comments

Comments
 (0)