diff --git a/examples/npm/elysia/package.json b/examples/npm/elysia/package.json index 3cc106f..30bc0f0 100644 --- a/examples/npm/elysia/package.json +++ b/examples/npm/elysia/package.json @@ -1,6 +1,5 @@ { "name": "elysia", - "version": "1.0.0", "type": "module", "main": "index.ts", "scripts": { @@ -10,4 +9,4 @@ "elysia": "^1.4.28" }, "devDependencies": {} -} \ No newline at end of file +} diff --git a/examples/npm/express/package.json b/examples/npm/express/package.json index 3c94cc8..27d1923 100644 --- a/examples/npm/express/package.json +++ b/examples/npm/express/package.json @@ -1,6 +1,5 @@ { "name": "express", - "version": "1.0.0", "type": "commonjs", "main": "index.cjs", "scripts": { diff --git a/examples/npm/hono/package.json b/examples/npm/hono/package.json index 0529b82..eb14a4f 100644 --- a/examples/npm/hono/package.json +++ b/examples/npm/hono/package.json @@ -1,6 +1,5 @@ { "name": "hono", - "version": "1.0.0", "type": "module", "main": "index.js", "scripts": { diff --git a/examples/npm/ky/package.json b/examples/npm/ky/package.json index 67ab714..0e96ad7 100644 --- a/examples/npm/ky/package.json +++ b/examples/npm/ky/package.json @@ -1,6 +1,5 @@ { "name": "ky", - "version": "1.0.0", "type": "module", "main": "index.js", "scripts": { @@ -10,4 +9,4 @@ "ky": "^1.14.3" }, "devDependencies": {} -} \ No newline at end of file +} diff --git a/examples/npm/lua/ant.lockb b/examples/npm/lua/ant.lockb new file mode 100644 index 0000000000000000000000000000000000000000..9f12ce56aaff97c80b2da622c94001f764e6a75d GIT binary patch literal 288 zcmeZq_YPoWU|;}Y1_lNO2L=WPZw3a22@DJj5{wWGlLN`4V~3RdqRf=c#610+(!{Ld zjFOUqVk>?9qSW-v;*z3Dy}W|ltYW?VqI7*UmHN669lC~k26`5HCFxagqxq5C0~6$c zF`#tnrionVy;}3WZ8~fCcamqxd*7(N7i!nu5==hTA^hj#%LQ858}Ipc7IyUB&J? Promise | void) { + try { + await fn(); + console.log(`✓ ${name}`); + } catch (err) { + console.error(`✗ ${name}`); + console.error(err); + } +} + +function convertBack(ret: unknown[]): [string, unknown] { + return [ret[0] as string, (ret[1] as LuaTable).toObject(true, true)]; +} + +await test('Can run basic Lua code', async () => { + const L = await LuaJS.newState(); + const ret = await L.run('return 1 + 2, "hello"'); + assert.deepEqual(ret, [3, 'hello']); +}); + +await test('Can pass JS types to Lua correctly', async () => { + const L = await LuaJS.newState(); + const ret = await L.run('return function(a) return type(a), a end'); + const retConvert = await L.run('return function(a) a = a:toTable(true, 10); return type(a), a end'); + + const func = (ret[0] as LuaFunction).getClosure(); + const funcConvert = (retConvert[0] as LuaFunction).getClosure(); + + assert.deepEqual(await func('hello world'), ['string', 'hello world']); + assert.deepEqual(await func(13), ['number', 13]); + assert.deepEqual(await func([1, 2, 3]), ['userdata', [1, 2, 3]]); + + assert.deepEqual(convertBack(await funcConvert([1, 2, true, undefined, null, , 3])), ['table', [1, 2, true, , , , 3]]); + assert.deepEqual(convertBack(await funcConvert({ a: 1, b: '2', c: true, d: undefined, e: null })), ['table', { a: 1, b: '2', c: true }]); + + assert.deepEqual(convertBack(await funcConvert({ a: 1, b: [4, { x: 5, y: [6, 9, 42] }, 6], c: true })), [ + 'table', + { a: 1, b: [4, { x: 5, y: [6, 9, 42] }, 6], c: true } + ]); +}); + +await test('allows awaiting JS promises', async () => { + const L = await LuaJS.newState(); + await L.run('return js.await'); +}); diff --git a/examples/npm/lua/package.json b/examples/npm/lua/package.json new file mode 100644 index 0000000..742052f --- /dev/null +++ b/examples/npm/lua/package.json @@ -0,0 +1,12 @@ +{ + "name": "lua", + "type": "module", + "main": "index.js", + "scripts": { + "start": "ant index.js" + }, + "dependencies": { + "@doridian/luajs": "^1.0.8" + }, + "devDependencies": {} +} diff --git a/examples/npm/preact/package.json b/examples/npm/preact/package.json index 135f0a2..561b468 100644 --- a/examples/npm/preact/package.json +++ b/examples/npm/preact/package.json @@ -1,6 +1,5 @@ { "name": "preact", - "version": "1.0.0", "type": "module", "main": "index.js", "scripts": { @@ -10,4 +9,4 @@ "preact": "^10.29.0", "esbuild": "^0.27.3" } -} \ No newline at end of file +} diff --git a/examples/npm/react/package.json b/examples/npm/react/package.json index 5909011..521dc92 100644 --- a/examples/npm/react/package.json +++ b/examples/npm/react/package.json @@ -1,6 +1,5 @@ { "name": "react", - "version": "1.0.0", "type": "module", "main": "index.js", "scripts": { diff --git a/examples/npm/undici/package.json b/examples/npm/undici/package.json index ec19387..ecca685 100644 --- a/examples/npm/undici/package.json +++ b/examples/npm/undici/package.json @@ -1,6 +1,5 @@ { "name": "undici", - "version": "1.0.0", "type": "module", "main": "index.js", "scripts": { @@ -10,4 +9,4 @@ "undici": "^7.24.7" }, "devDependencies": {} -} \ No newline at end of file +}