contrib: introduce ucode-mod-lua 5818/head
authorJo-Philipp Wich <jo@mein.io>
Thu, 19 May 2022 15:10:17 +0000 (17:10 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 30 May 2022 12:25:33 +0000 (14:25 +0200)
commit70ff5c3c4a0c30f15cc0d115011f5d9ac6146ef6
treea4d95d0f8892519b18562f5a9ae1bc6f244e6c37
parentd6dbedd9e2c77f44be0f64ee8128401a293f77f4
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>
contrib/package/ucode-mod-lua/Makefile [new file with mode: 0644]
contrib/package/ucode-mod-lua/src/lua.c [new file with mode: 0644]