diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-05-19 17:10:17 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-05-30 14:25:33 +0200 |
commit | 70ff5c3c4a0c30f15cc0d115011f5d9ac6146ef6 (patch) | |
tree | a4d95d0f8892519b18562f5a9ae1bc6f244e6c37 /modules/luci-base/luasrc/sgi | |
parent | d6dbedd9e2c77f44be0f64ee8128401a293f77f4 (diff) |
contrib: introduce ucode-mod-lua
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>
Diffstat (limited to 'modules/luci-base/luasrc/sgi')
0 files changed, 0 insertions, 0 deletions