Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "demoon", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Lua + Node", | ||
@@ -16,4 +16,4 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"wasmoon": "1.6.1" | ||
"wasmoon": "1.7.0" | ||
} | ||
} |
@@ -47,4 +47,3 @@ # demoon | ||
res:write('Hello World!'); | ||
-- because end is a lua keyword you have to put the '_' | ||
res:_end(); | ||
res['end'](); | ||
end)):listen(port); | ||
@@ -51,0 +50,0 @@ |
const { LuaFactory } = require('wasmoon') | ||
const path = require('path') | ||
const { walk } = require('./file') | ||
const fs = require('fs').promises | ||
const registerDirectory = async (factory, dir) => { | ||
for await (const file of walk(dir)) { | ||
await factory.mountFile(file, await fs.readFile(file)) | ||
} | ||
} | ||
const start = async (entryFile) => { | ||
const factory = new LuaFactory() | ||
const factory = new LuaFactory(undefined, process.env) | ||
await factory.mountFile(path.resolve(process.cwd(), entryFile), await fs.readFile(entryFile)) | ||
await registerDirectory(factory, path.resolve(__dirname, "std")) | ||
const fullEntryFile = path.resolve(process.cwd(), entryFile) | ||
const fullStdFile = path.resolve(__dirname, "std.lua") | ||
const lua = await factory.createEngine({ injectObjects: true }) | ||
await factory.mountFile(fullEntryFile, await fs.readFile(fullEntryFile)) | ||
await factory.mountFile(fullStdFile, await fs.readFile(fullStdFile)) | ||
lua.global.set('new', (constructor, ...args) => new constructor(...args)) | ||
lua.global.set('global', global) | ||
lua.global.set('mountFile', factory.mountFileSync.bind(factory)) | ||
lua.global.set('jsRequire', (modulename, metaDirectory) => { | ||
if (modulename.startsWith('.')) { | ||
modulename = path.resolve(metaDirectory, '..', modulename) | ||
} | ||
const engine = await factory.createEngine({ injectObjects: true }) | ||
return require(modulename) | ||
}) | ||
engine.global.set('new', (constructor, ...args) => new constructor(...args)) | ||
engine.global.set('global', global) | ||
engine.global.set('mountFile', factory.mountFileSync.bind(factory)) | ||
engine.global.set('jsRequire', (modulename, metaDirectory) => { | ||
if (modulename.startsWith('.')) { | ||
modulename = path.resolve(metaDirectory, '..', modulename) | ||
} | ||
await lua.doFile(path.resolve(__dirname, "std/main.lua")) | ||
await lua.doFile(path.resolve(process.cwd(), entryFile)) | ||
return require(modulename) | ||
}) | ||
try { | ||
engine.doFileSync(fullStdFile) | ||
const thread = engine.global.newThread() | ||
thread.loadFile(fullEntryFile) | ||
await thread.run(0) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} | ||
module.exports = { start } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6069
7
28
51
+ Addedwasmoon@1.7.0(transitive)
- Removedwasmoon@1.6.1(transitive)
Updatedwasmoon@1.7.0