Skip to content

Commit

Permalink
perf: format console.log lua table
Browse files Browse the repository at this point in the history
  • Loading branch information
X3ZvaWQ committed Feb 15, 2024
1 parent 023c98a commit 9a5901f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 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.2",
"version": "1.18.3",
"description": "A real lua 5.1 VM with JS bindings made with webassembly",
"main": "dist/index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DictType, mapTransform } from './utils/map-transform';
import { LUA_REGISTRYINDEX, LuaType } from './definitions';
import { inspect } from 'util';
import LuaThread from './thread';

export class LuaTable {
Expand All @@ -16,6 +17,10 @@ export class LuaTable {
this.pointer = pointer;
}

[inspect.custom](): string {
return this.toString();
}

public $get(key: any): any {
return this.getTableValue(key);
}
Expand All @@ -41,7 +46,7 @@ export class LuaTable {
}

public toString(): string {
return `[LuaTable *${this.ref} 0x${this.pointer.toString(16)}]`;
return `[LuaTable 0x${this.pointer.toString(16)} *${this.ref}]`;
}

private getTableValue(key: any): any {
Expand Down
25 changes: 11 additions & 14 deletions test/debug.mjs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
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();

class S {
pp() {
console.log('pp');
}
}
const s = new S();
lua.ctx.s = {
name: 123,
};

lua.ctx.s = JsType.decorate(s)
.tostring(() => '2333')
.index((target, key) => target[key])
.newindex((target, key, value) => {
target[key] = value;
});
lua.ctx.s.a = {};
lua.ctx.s.a.b = {};
lua.ctx.s.a.b.c = {};
lua.ctx.s.a.b.c.name = '233';

console.log(lua.ctx.s.a.b.c);
await lua.doString(`
print(s)
print(s.a.b.c)
print(s.a.b.c.name)
`);

0 comments on commit 9a5901f

Please sign in to comment.