flua
v0.2.2
Published
Easy scriptable Lua in the browser with fengari.
Downloads
4
Readme
flua
Fengari is great, but if you're unfamiliar with Lua it's useless. It simply tells you to read the Lua C documentation and if you're brave enough to read that you'll end up not understanding anything about the Lua stack, pushing stuff to the stack and who knows what. There's a video that will teach you that in 40 minutes (or less if you accelerate it), but you may not that have these minutes. And you may not want to go to the trouble of converting JavaScript objects into Lua and vice-versa.
npm install flua
const flua = require('flua')
try {
let {tojs} = flua.runWithGlobals({
fromjs: 10,
multiply: (value, times) => value * times
}, 'tojs = multiply(fromjs, 3)', ['tojs'])
console.log(tojs) // 30
} catch (e) {
console.log(e)
}
(When passing functions from JavaScript to Lua, you can make them return an array. In that case it will translate into a Lua function that returns multiple values. If you want a Lua function that returns an array-table instead of multiple values, return an array with your desired array inside.)
If you want more control, see example.js or read the source for runWithGlobals
.
Don't install fengari from npm. What you need is fengari-web. But since it doesn't work with Browserify you can include it with
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fengari-web.js"></script>
and then you can use window.fengari
instead of require('fengari')
(on example.js I'm using a browserify shim).