Skip to content

Commit adb990e

Browse files
committed
Update wasmoon to use builtin proxies, add CI
1 parent 72d60f0 commit adb990e

File tree

7 files changed

+47
-136
lines changed

7 files changed

+47
-136
lines changed

.github/workflows/publish.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Use Node.js 14.x
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: 14.x
17+
- uses: mymindstorm/setup-emsdk@v7
18+
- run: npm ci
19+
- uses: JS-DevTools/npm-publish@v1
20+
with:
21+
token: ${{ secrets.NPM_TOKEN }}

example/main.lua

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env demoon
12
-- you can require JS module files
23
local jssleep = require('./sleep.js')
34
-- you can require node modules
@@ -16,8 +17,7 @@ http.createServer(async(function (req, res)
1617
jssleep(1000):await()
1718

1819
res:write('Hello World!'); -- write a response to the client
19-
-- because end is a lua keyword you have to put the '_'
20-
res:_end(); -- end the response
20+
res['end'](); -- end the response
2121
end)):listen(port); -- the server object listens on port 8080
2222

2323
print('Your server is running on port ' .. port .. '!')

package-lock.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "demoon",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "Lua + Node",
55
"main": "src/index.js",
66
"bin": {
@@ -13,6 +13,6 @@
1313
"lua"
1414
],
1515
"dependencies": {
16-
"wasmoon": "1.5.0"
16+
"wasmoon": "1.6.1"
1717
}
1818
}

src/index.js

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const { LuaFactory, decorate } = require('wasmoon')
1+
const { LuaFactory } = require('wasmoon')
22
const path = require('path')
33
const { walk } = require('./file')
44
const fs = require('fs').promises
5-
const proxy = require('./proxy')
65

76
const registerDirectory = async (factory, dir) => {
87
for await (const file of walk(dir)) {
@@ -18,28 +17,19 @@ const start = async (entryFile) => {
1817

1918
const lua = await factory.createEngine({ injectObjects: true })
2019

21-
lua.global.set('new', constructor => new constructor)
22-
lua.global.set('global', decorate(global, {
23-
reference: true,
24-
metatable: proxy
25-
}))
20+
lua.global.set('new', (constructor, ...args) => new constructor(...args))
21+
lua.global.set('global', global)
2622
lua.global.set('mountFile', factory.mountFileSync.bind(factory))
2723
lua.global.set('jsRequire', (modulename, metaDirectory) => {
28-
if (modulename.startsWith('.')) {
29-
modulename = path.resolve(metaDirectory, '..', modulename)
30-
}
24+
if (modulename.startsWith('.')) {
25+
modulename = path.resolve(metaDirectory, '..', modulename)
26+
}
3127

32-
return decorate(require(modulename), {
33-
reference: true,
34-
metatable: proxy
28+
return require(modulename)
3529
})
36-
})
37-
38-
const module = await factory.getModule()
39-
module.module.FS.chdir(process.cwd())
4030

4131
await lua.doFile(path.resolve(__dirname, "std/main.lua"))
42-
await lua.doFile(entryFile)
32+
await lua.doFile(path.resolve(process.cwd(), entryFile))
4333
}
4434

4535
module.exports = { start }

src/proxy.js

-105
This file was deleted.

src/std/main.lua

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ table.insert(package.searchers, function(moduleName)
5151
if success then return function() return result end end
5252
end)
5353

54+
-- replace the origin getenv by the nodejs one
55+
function os.getenv(varname)
56+
return process.env[varname]
57+
end
58+
5459
-- set the nodejs global as fallback to default lua global
5560
setmetatable(_G, {
5661
__index = function(t, k) return global[k] end

0 commit comments

Comments
 (0)