Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blixt/js-luaworker
Package for running a Lua VM in a Web Worker.
https://github.com/blixt/js-luaworker
Last synced: about 1 month ago
JSON representation
Package for running a Lua VM in a Web Worker.
- Host: GitHub
- URL: https://github.com/blixt/js-luaworker
- Owner: blixt
- License: mit
- Created: 2014-03-09T16:37:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-03-10T21:24:12.000Z (over 10 years ago)
- Last Synced: 2024-10-07T04:49:13.671Z (about 1 month ago)
- Language: C
- Homepage: http://blixt.github.io/js-luaworker/
- Size: 672 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Lua Worker
==========Package for running a Lua VM in a Web Worker.
**Demo:** http://blixt.github.io/js-luaworker/
Example
-------If you prebuilt the `worker.js` file, you can specify its location when
calling the `luaworker` module function:```js
var lua = require('luaworker')('worker.js');
lua.execute('name = "Lua"');
lua.execute('print("Hello from " .. name .. "!")', function (err, buffer) {
console.log(buffer);
});
```To be able to run this in a browser, you need to use a framework that
supports CommonJS modules (for example: [Browserify][]).Using this package
------------------To get the necessary files from this package, install it with [NPM][]:
```bash
npm install --save luaworker
```As stated above, you need to first package this code so that it can run
in a browser. You can do this with, for example, [Browserify][].Here's how you'd create the JavaScript files to run in your browser,
assuming you are using the code in the *Example* section above:```bash
# Bundle the Worker code into its own file:
browserify node_modules/luaworker/worker.js -o worker.js
# Put the code from the Example section into main.js, then run this:
browserify main.js -o app.js
```If you run this, you should see the output "Hello from Lua!" in your
console.Note that this hasn't been optimized yet, so if you don't minimize your
code (by using [UglifyJS][], for example), you may end up with a huge
`worker.js` file.Building
--------To build the required JavaScript, you need to have [Emscripten][] in
your PATH. To build, simply run `./build`.The work in `emlua.patch` is borrowed from kripken's [lua.vm.js][].
**Note:** This does not include the Lua → JS bridge, since allowing
access to JavaScript from Lua might not always be desirable.[Browserify]: http://browserify.org/
[Emscripten]: https://github.com/kripken/emscripten
[lua.vm.js]: https://github.com/kripken/lua.vm.js
[NPM]: https://www.npmjs.org/
[UglifyJS]: https://github.com/mishoo/UglifyJS