Skip to content

Commit

Permalink
fix: some unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
X3ZvaWQ committed Jan 21, 2024
1 parent b781517 commit 784027e
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 200 deletions.
15 changes: 15 additions & 0 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ export default class LuaThread {
return mapTransform(table);
}

public call(name: string, ...args: any[]): MultiReturn {
const type = this.luaApi.lua_getglobal(this.address, name);
if (type !== LuaType.Function) {
throw new Error(`A function of type '${type}' was pushed, expected is ${LuaType.Function}`);
}

for (const arg of args) {
this.pushValue(arg);
}

const base = this.getTop() - args.length - 1; // The 1 is for the function to run
this.luaApi.lua_call(this.address, args.length, LUA_MULTRET);
return this.getStackValues(base);
}

public pop(count = 1): void {
this.luaApi.lua_pop(this.address, count);
}
Expand Down
Loading

0 comments on commit 784027e

Please sign in to comment.