Skip to content

Commit

Permalink
Added support for indexing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sewbacca committed Oct 5, 2022
1 parent a638c2f commit ca5162a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions debugger/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,16 @@ export namespace Debugger {
}
}
}

debug.setmetatable(() => { }, {
__index(key: string) {
const info = debug.getinfo(this, "fu");
if (!info) return undefined;
const val = getUpvalues(info).vars[key];
if (!val) return undefined;
return val.val;
}
});
};

export function clearHook(): void {
Expand All @@ -1183,6 +1193,8 @@ export namespace Debugger {
debug.sethook(thread);
}
}

debug.setmetatable(() => { }, undefined);
}

const breakInCoroutinesEnv: LuaDebug.BreakInCoroutinesEnv = "LOCAL_LUA_DEBUGGER_BREAK_IN_COROUTINES";
Expand Down
9 changes: 6 additions & 3 deletions extension/luaDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,10 @@ export class LuaDebugSession extends LoggingDebugSession {
return {success: true, value: "nil", variablesReference: 0};
} else if (msg.results.length === 1) {
const result = msg.results[0];
const variablesReference = (result.type === "table" || result.type === "function") ? this.variableHandles.create(expression) : 0;
const variablesReference = (result.type === "table" || result.type === "function")
? this.variableHandles.create(expression)
: 0;

return {success: true, value: this.getValueString(result), variablesReference};
} else {
const variablesReference = this.variableHandles.create(`@({${expression}})`);
Expand All @@ -718,7 +721,7 @@ export class LuaDebugSession extends LoggingDebugSession {
? `[error: ${this.filterErrorMessage(variable.error)}]`
: `(${variable.value ?? ""})`;
ref = variable.type === "table" ? this.variableHandles.create("@({...})") : 0;
} else if (variable.type === "table") {
} else if (variable.type === "table" || variable.type === "function") {
valueStr = this.getValueString(variable);
ref = this.variableHandles.create(refName);
} else {
Expand All @@ -728,7 +731,7 @@ export class LuaDebugSession extends LoggingDebugSession {
const indexedVariables = typeof variable.length !== "undefined" && variable.length > 0
? variable.length + 1
: variable.length;
if (variable.type === "table") {
if (variable.type === "table" || variable.type === "function") {
return new Variable(name, valueStr, ref, indexedVariables, 1);
} else {
return new Variable(name, valueStr, ref, indexedVariables);
Expand Down

0 comments on commit ca5162a

Please sign in to comment.