Skip to content

Commit 079124e

Browse files
committed
writing globals to env in interpreter mode
fixes Global variables do not seem to carry over to loaded modules tomblind#58
1 parent 6ffd2b3 commit 079124e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

debugger/lldebugger.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ export function runFile(filePath: unknown, breakImmediately?: boolean, arg?: unk
6363
if (breakImmediately !== undefined && typeof breakImmediately !== "boolean") {
6464
throw `expected boolean as second argument to runFile, but got '${type(breakImmediately)}'`;
6565
}
66-
const env = setmetatable({arg}, {__index: _G});
66+
const env = setmetatable(
67+
{arg},
68+
{
69+
__index: _G,
70+
__newindex: (self: unknown, key: keyof typeof _G, value: unknown) => { _G[key] = value; }
71+
}
72+
);
6773
const [func] = luaAssert(...loadLuaFile(filePath, env));
6874
return Debugger.debugFunction(func as Debugger.DebuggableFunction, breakImmediately, arg ?? []);
6975
}

0 commit comments

Comments
 (0)