@mikuroxina/do-lua
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

do-lua

The Lua runtime for Node.js.

Usage

const { doFile, doString } = require('do-lua');

const program = `
print("Hello, World!")
`;

doString(program).then(() => {
  console.log("Done doString");
})
doFile('examples/test1.lua').then(() => {
  console.log("Done doFile");
})

You cannot use this in functions of the passing table on loadProgram. Use arrow function instead of that.

const { loadProgram } = require('do-lua');

const state = loadProgram(`
obj.ox = 50;
obj.mes("Hello, World!")
`);
let message = '';
const table = {
  ox: 0,
  mes: (text) => {
    message += text; // `this` cannot be used but can capture variables.
  }
};
state.setTable('obj', table);

state.run().then((G) => { // G is global table exclusive "package" and "_G"
  console.log("ox: ", G.obj.ox); // 50
  console.log("Message: ", message); // Hello, World!
});

/@mikuroxina/do-lua/

    Package Sidebar

    Install

    npm i @mikuroxina/do-lua

    Weekly Downloads

    0

    Version

    0.1.1

    License

    Apache-2.0

    Unpacked Size

    28.8 kB

    Total Files

    12

    Last publish

    Collaborators

    • mikuroxina