0.0.12 • Published 12 months ago

@cbrewster/luna v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@cbrewster/luna

Node.js bindings to Lua.

import { Lua, LuaTable } from '@cbrewster/luna';

(async () => {
  const lua = new Lua();

  console.log(await lua.doString("x = 1")); // null
  console.log(await lua.doString("return x")); // 1

  try {
    await lua.doString("this is a syntax error"); // Error!
  } catch (e) {
    console.log(e); 
  }
  
  console.log(await lua.doString("return 1 + 2")); // 3
  console.log(await lua.doString(`return "abc"`)); // "abc"

  const table = await lua.doString(`return {key = "value", foo = "bar"}`);
  if (table instanceof LuaTable) {
    table.forEach((key, val) => {
      console.log(`key: ${key} val: ${val}`);
    });
  }
  
  const selfReference = await lua.doString("x = {} \n x.self = x \n return x");
  if (selfReference instanceof LuaTable) {
    selfReference.forEach((key, val) => {
      console.log(`key: ${key} val: ${val}`);
      if (val?.toString() === selfReference.toString()) {
        console.log("we have a cycle!");
        console.log("Table: ", selfReference.toString());
      }
    });
  }

  lua.close();
})()
0.0.12

12 months ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago