Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

demoon

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

demoon - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

src/std.lua

4

package.json
{
"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 }
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc