Skip to content

Commit ba773dc

Browse files
committed
ensuring getmetatable exists during evals
1 parent 4be797d commit ba773dc

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

debugger/debugger.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ export namespace Debugger {
363363
return mappedExpression;
364364
}
365365

366+
const metatableAccessor: LuaDebug.MetatableAccessor = "lldbg_getmetatable";
367+
366368
function execute(
367369
statement: string,
368370
level: number,
@@ -384,12 +386,14 @@ export namespace Debugger {
384386
{},
385387
{
386388
__index(this: unknown, name: string) {
389+
if (name === metatableAccessor) {
390+
return getmetatable;
391+
}
387392
const variable = locs.vars[name] ?? ups.vars[name];
388393
if (variable !== undefined) {
389394
return variable.val;
390-
} else {
391-
return fenv[name];
392395
}
396+
return fenv[name];
393397
},
394398
__newindex(this: unknown, name: string, val: unknown) {
395399
const variable = locs.vars[name] ?? ups.vars[name];

debugger/protocol.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ declare namespace LuaDebug {
111111
type StartToken = "@lldbg|";
112112
type EndToken = "|lldbg@";
113113

114+
type MetatableAccessor = "lldbg_getmetatable";
115+
114116
type ScriptRootsEnv = "LOCAL_LUA_DEBUGGER_SCRIPT_ROOTS";
115117
type BreakInCoroutinesEnv = "LOCAL_LUA_DEBUGGER_BREAK_IN_COROUTINES";
116118
type StepUnmappedLinesEnv = "LOCAL_LUA_DEBUGGER_STEP_UNMAPPED_LINES";

extension/luaDebugSession.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const enum OutputCategory {
6868
const maxStackCount = 100;
6969
const metatableDisplayName = "[[metatable]]";
7070
const tableLengthDisplayName = "[[length]]";
71+
const metatableAccessor: LuaDebug.MetatableAccessor = "lldbg_getmetatable";
7172
const envVariable = "LOCAL_LUA_DEBUGGER_VSCODE";
7273
const filePathEnvVariable = "LOCAL_LUA_DEBUGGER_FILEPATH";
7374
const scriptRootsEnvVariable: LuaDebug.ScriptRootsEnv = "LOCAL_LUA_DEBUGGER_SCRIPT_ROOTS";
@@ -520,7 +521,9 @@ export class LuaDebugSession extends LoggingDebugSession {
520521
}
521522

522523
if (typeof vars.metatable !== "undefined" && typeof baseName !== "undefined") {
523-
variables.push(this.buildVariable(vars.metatable, `getmetatable(${baseName})`, metatableDisplayName));
524+
variables.push(
525+
this.buildVariable(vars.metatable, `${metatableAccessor}(${baseName})`, metatableDisplayName)
526+
);
524527
}
525528

526529
if (typeof vars.length !== "undefined" && !isMultiResult) {

0 commit comments

Comments
 (0)