Embed the Lua scripting engine into your Haxe application
- c++ (tested on macOS and windows)
- js (tested on Chrome)
- nodejs
// create an instance
var lua = new vm.lua.Lua();
// set global variables
lua.setGlobalVar('square', function(v) return v * v);
lua.setGlobalVar('foo', 2);
// run a script
lua.run('return square(foo)'); // gives you 4
// supply an object as second paramter to run() to set global vars
lua.run('return bar', {bar: 2}); // gives you 2
// run function
lua.run('function add(a, b) \n return a + b \n end'); // first we create a lua function
lua.call('add', [1, 2]); // gives you 3
// destroy when done with the instance
lua.destroy();When targeting C++ we compile the Lua runtime from its C source code.
- Install haxelib: linc_lua
- Add
-lib linc_luato your haxe build
When targeting JS we utilize Fengari, which is the Lua VM written in pure JavaScript.
You can choose to either build a standalone js file for Fengari or require it in your project.
- Install haxelib: hxjs-fengari
- Git clone https://github.com/fengari-lua/fengari
- Run
yarn && yarn run build - Add the output file (
dist/fengari.js) to your project using a<script>tag in html - Add
-lib hxjs-fengari -D fengari_globalto your haxe build
- Install haxelib: hxjs-fengari
yarn add https://github.com/fengari-lua/fengari- Add
-lib hxjs-fengarito your haxe build
- Implement/test coroutines