diff --git a/package-lock.json b/package-lock.json index dc262cb..fdca07c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "wasmoon-lua5.1", - "version": "1.18.6", + "version": "1.18.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "wasmoon-lua5.1", - "version": "1.18.6", + "version": "1.18.7", "license": "MIT", "dependencies": { "@types/emscripten": "^1.39.10", diff --git a/package.json b/package.json index 847a4b5..47a97ab 100755 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/thread.ts b/src/thread.ts index 0c468d4..0180bd4 100755 --- a/src/thread.ts +++ b/src/thread.ts @@ -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)); } diff --git a/test/debug.mjs b/test/debug.mjs index 8398675..8f7756b 100644 --- a/test/debug.mjs +++ b/test/debug.mjs @@ -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()`);