Skip to content

Commit

Permalink
perf: remove array-table index transform
Browse files Browse the repository at this point in the history
  • Loading branch information
X3ZvaWQ committed Jan 27, 2024
1 parent 8bd63fb commit dbd62a2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
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.16.4",
"version": "1.17.0",
"description": "A real lua 5.1 VM with JS bindings made with webassembly",
"main": "dist/index.js",
"scripts": {
Expand Down
8 changes: 2 additions & 6 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export default class LuaThread {

try {
for (const key of arrIndexs) {
this.pushValue(key + 1, options);
this.pushValue(key, options);
this.pushValue(object[key], options);
this.luaApi.lua_settable(this.address, -3);
}
Expand Down Expand Up @@ -358,11 +358,7 @@ export default class LuaThread {
const key = this.getValue(-2, { refs: options.refs });
const value = this.getValue(-1, { refs: options.refs });

if (typeof key === 'number') {
table.set(key - 1, value);
} else {
table.set(key, value);
}
table.set(key, value);
this.pop();
}

Expand Down
14 changes: 2 additions & 12 deletions test/debug.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { JsType, Lua } from '../dist/index.js';
import { Lua } from '../dist/index.js';

// This file was created as a sandbox to test and debug on vscode
const lua = await Lua.create();

lua.ctx.null = JsType.decorate(null).tostring(() => 'null');

lua.global.loadString(`
local args = { ... }
assert(args[1] == null, string.format("expected first argument to be null, got %s", tostring(args[1])))
return null, args[1], tostring(null)
`);
lua.global.pushValue(null);
const res = await lua.global.run(1);
expect(res).to.deep.equal([null, null, 'null']);
await lua.doString(`print('Hello World!')`);

0 comments on commit dbd62a2

Please sign in to comment.