MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

add lua example

+64 -11
+1 -2
examples/npm/elysia/package.json
··· 1 1 { 2 2 "name": "elysia", 3 - "version": "1.0.0", 4 3 "type": "module", 5 4 "main": "index.ts", 6 5 "scripts": { ··· 10 9 "elysia": "^1.4.28" 11 10 }, 12 11 "devDependencies": {} 13 - } 12 + }
-1
examples/npm/express/package.json
··· 1 1 { 2 2 "name": "express", 3 - "version": "1.0.0", 4 3 "type": "commonjs", 5 4 "main": "index.cjs", 6 5 "scripts": {
-1
examples/npm/hono/package.json
··· 1 1 { 2 2 "name": "hono", 3 - "version": "1.0.0", 4 3 "type": "module", 5 4 "main": "index.js", 6 5 "scripts": {
+1 -2
examples/npm/ky/package.json
··· 1 1 { 2 2 "name": "ky", 3 - "version": "1.0.0", 4 3 "type": "module", 5 4 "main": "index.js", 6 5 "scripts": { ··· 10 9 "ky": "^1.14.3" 11 10 }, 12 11 "devDependencies": {} 13 - } 12 + }
examples/npm/lua/ant.lockb

This is a binary file and will not be displayed.

+48
examples/npm/lua/lua.ts
··· 1 + import assert from 'node:assert'; 2 + import { LuaJS, LuaFunction, LuaTable } from '@doridian/luajs'; 3 + 4 + async function test(name: string, fn: () => Promise<void> | void) { 5 + try { 6 + await fn(); 7 + console.log(`โœ“ ${name}`); 8 + } catch (err) { 9 + console.error(`โœ— ${name}`); 10 + console.error(err); 11 + } 12 + } 13 + 14 + function convertBack(ret: unknown[]): [string, unknown] { 15 + return [ret[0] as string, (ret[1] as LuaTable).toObject(true, true)]; 16 + } 17 + 18 + await test('Can run basic Lua code', async () => { 19 + const L = await LuaJS.newState(); 20 + const ret = await L.run('return 1 + 2, "hello"'); 21 + assert.deepEqual(ret, [3, 'hello']); 22 + }); 23 + 24 + await test('Can pass JS types to Lua correctly', async () => { 25 + const L = await LuaJS.newState(); 26 + const ret = await L.run('return function(a) return type(a), a end'); 27 + const retConvert = await L.run('return function(a) a = a:toTable(true, 10); return type(a), a end'); 28 + 29 + const func = (ret[0] as LuaFunction).getClosure(); 30 + const funcConvert = (retConvert[0] as LuaFunction).getClosure(); 31 + 32 + assert.deepEqual(await func('hello world'), ['string', 'hello world']); 33 + assert.deepEqual(await func(13), ['number', 13]); 34 + assert.deepEqual(await func([1, 2, 3]), ['userdata', [1, 2, 3]]); 35 + 36 + assert.deepEqual(convertBack(await funcConvert([1, 2, true, undefined, null, , 3])), ['table', [1, 2, true, , , , 3]]); 37 + assert.deepEqual(convertBack(await funcConvert({ a: 1, b: '2', c: true, d: undefined, e: null })), ['table', { a: 1, b: '2', c: true }]); 38 + 39 + assert.deepEqual(convertBack(await funcConvert({ a: 1, b: [4, { x: 5, y: [6, 9, 42] }, 6], c: true })), [ 40 + 'table', 41 + { a: 1, b: [4, { x: 5, y: [6, 9, 42] }, 6], c: true } 42 + ]); 43 + }); 44 + 45 + await test('allows awaiting JS promises', async () => { 46 + const L = await LuaJS.newState(); 47 + await L.run('return js.await'); 48 + });
+12
examples/npm/lua/package.json
··· 1 + { 2 + "name": "lua", 3 + "type": "module", 4 + "main": "index.js", 5 + "scripts": { 6 + "start": "ant index.js" 7 + }, 8 + "dependencies": { 9 + "@doridian/luajs": "^1.0.8" 10 + }, 11 + "devDependencies": {} 12 + }
+1 -2
examples/npm/preact/package.json
··· 1 1 { 2 2 "name": "preact", 3 - "version": "1.0.0", 4 3 "type": "module", 5 4 "main": "index.js", 6 5 "scripts": { ··· 10 9 "preact": "^10.29.0", 11 10 "esbuild": "^0.27.3" 12 11 } 13 - } 12 + }
-1
examples/npm/react/package.json
··· 1 1 { 2 2 "name": "react", 3 - "version": "1.0.0", 4 3 "type": "module", 5 4 "main": "index.js", 6 5 "scripts": {
+1 -2
examples/npm/undici/package.json
··· 1 1 { 2 2 "name": "undici", 3 - "version": "1.0.0", 4 3 "type": "module", 5 4 "main": "index.js", 6 5 "scripts": { ··· 10 9 "undici": "^7.24.7" 11 10 }, 12 11 "devDependencies": {} 13 - } 12 + }