i0x0 / node-lua

run lua from js and vice versa (eventually)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-lua

something probably only roblox devs would use

Docs

To install (do i feel like pushing to npm? mmmm no?)

npm install git+https://github.com/i0x0/node-lua.git

Everything else

import Lua from "node-lua"
import assert from "assert"
// make a new instance of Lua
let lua = new Lua()

//probably a recommended function for simple logging lua errors
const luaError = (err: string, x: () => {}) => console.error("lua error:" + err)

//go-lang way of error handling
let { err } = lua.load("function hi() return "hello" end")

// if nothing logs then it worked perfectly
if (err) {
  luaError(err)
}

// call the same function we made
let { err, value } = lua.call("hi()")
if (err) {
  luaError(err)
} else {
  assert.equal(value, "hello")
}

// add a variable from ts to lua (only supports strings for now)
let { err } = lua.add("hello", "world")
if (err) {
  luaError(err)
}

// getting the variable we added earlier
let { err, value } = lua.call("hello")
if (err) {
  luaError(err)
} else {
  assert.equal(value, "world")
}

About

run lua from js and vice versa (eventually)


Languages

Language:Rust 94.0%Language:JavaScript 6.0%