summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/ucode-mod-lua/Makefile
AgeCommit message (Collapse)Author
2022-05-30contrib: introduce ucode-mod-luaJo-Philipp Wich
The ucode-mod-lua library provides an ucode-to-Lua bridge and a set of functions to instantiate Lua VMs, invoke Lua functions as well as exchanging data structures between ucode and Lua. Example usage: #!/usr/bin/ucode 'use strict'; const lua = require("lua"); let vm = lua.create(); vm.set({ hello: function(...args) { print(`A ucode "Hello world" function called from Lua! Got arguments: ${args}\n`); }, data_from_ucode: { bool: true, float: 1.3, int: 0x11223344, string: "Hello from ucode!", array: [ 1, 2, 3, null, 5 ], object: { apple: "green", banana: "yellow", [5]: "foo", [-1]: null, nested: { a: [ 5, 6 ], b: { c: NaN } } }, regexp: /foo/ } }); vm.invoke("hello", true, 123, "Foo"); vm.eval('print("Print from Lua!", data_from_ucode.int * data_from_ucode.float);'); try { vm.invoke("error", "Throwing a Lua exception..."); } catch (e) { print(`Caught exception: ${e}\n`); } print(`Lua VM version is: ${vm.get('_G', '_VERSION').value()}\n`); Signed-off-by: Jo-Philipp Wich <jo@mein.io>