Skip to content

Commit

Permalink
publish: 1.18.5
Browse files Browse the repository at this point in the history
  • Loading branch information
X3ZvaWQ committed Feb 15, 2024
1 parent 0bf072a commit 15dea0f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 43 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.4",
"version": "1.18.5",
"description": "A real lua 5.1 VM with JS bindings made with webassembly",
"main": "dist/index.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ export default class LuaThread {
}

const func = (...args: any[]): any => {
if (!func.$isAlive()) {
throw new Error('Tried to call a function that has been destroyed');
}
if (this.isClosed()) {
console.warn('Tried to call a function after closing lua state');
return;
Expand All @@ -250,11 +253,14 @@ export default class LuaThread {
thread.close();
}
};
func.$isAlive = () => true;
func.$destroy = () => {
this.luaApi.luaL_unref(this.address, LUA_REGISTRYINDEX, funcRef);
this.luaApi.pointerRefs.delete(pointer);
func.$isAlive = () => false;
};
this.luaApi.pointerRefs.set(pointer, func);

return func;
}

Expand Down
51 changes: 11 additions & 40 deletions test/debug.mjs
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
import { Lua } from '../dist/index.js';
// This file was created as a sandbox to test and debug on vscode

// const lua = await Lua.create();

// function test() {
// return 1234;
// }

// for (const index of Array.from({ length: 1 }, (_, i) => i + 1)) {
// console.log(index);
// lua.ctx.test = test;
// for (const i of Array.from({ length: 50 }, (_, i) => i + 1)) {
// await lua.doString('test()');
// await lua.doString(`print(test.x)`);
// await lua.doString(`test.x = ${i}`);
// }
// }

class TestClass {
static hello() {
return 'world';
}

constructor(name) {
this.name = name;
}
const lua = await Lua.create();

getName() {
return this.name;
}
function test() {
return 1234;
}

toString() {
return `TestClass<${this.name}>`;
for (const index of Array.from({ length: 1 }, (_, i) => i + 1)) {
console.log(index);
lua.ctx.test = test;
for (const i of Array.from({ length: 50 }, (_, i) => i + 1)) {
await lua.doString('test()');
await lua.doString(`print(test.x)`);
await lua.doString(`test.x = ${i}`);
}
}

const lua = await Lua.create();

lua.ctx.TestClass = {
create: (name) => new TestClass(name),
};
const res = await lua.doString(`
local instance = TestClass.create("demo name 2")
return instance.getName()
`);
console.log(res);

0 comments on commit 15dea0f

Please sign in to comment.