Skip to content

Commit

Permalink
feat: get global var pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
X3ZvaWQ committed Feb 15, 2024
1 parent 724ec92 commit 23cef80
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wasmoon-lua5.1",
"version": "1.18.6",
"version": "1.18.7",
"description": "A real lua 5.1 VM with JS bindings made with webassembly",
"main": "dist/index.js",
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,13 @@ export default class LuaThread {
}

//============调试用
public getGlobalPointer(name: string): Pointer {
this.luaApi.lua_getglobal(this.address, name);
const pointer = this.getPointer(-1);
this.pop();
return pointer;
}

public getPointer(index: number): Pointer {
return new Pointer(this.luaApi.lua_topointer(this.address, index));
}
Expand Down
19 changes: 13 additions & 6 deletions test/debug.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import { Lua } from '../dist/index.js';

const lua = await Lua.create();

lua.ctx.a = { name: 'a' };
lua.ctx.a.b = { name: 'b' };
lua.ctx.a.b.c = { name: 'c' };
lua.ctx.a.b.c.d = { name: 'd' };
await lua.doString(`
function Apply()
function Apply()
print(123)
end
end
`);

lua.global.dumpStack();
console.log(lua.global.getValue(-1).$detach());
console.log(lua.global.getGlobalPointer('Apply'));
await lua.doString(`Apply()`);
console.log(lua.global.getGlobalPointer('Apply'));
await lua.doString(`Apply()`);
console.log(lua.global.getGlobalPointer('Apply'));
await lua.doString(`Apply()`);

0 comments on commit 23cef80

Please sign in to comment.