Lua convenience library for nim



luna.nim is a convenience library for implementing Lua scripting in the nim language.
I created luna with game engines in mind, though it probably has potential for more applications.
If you think something could be done better, please contribute! Even simple suggestions are welcome.


# example.nim

import lua
import luna

const lua_code = """
function example_lua_function()
	return { hi = "hello" }

# set up Lua state like normal
let L = newstate()
dostring(L, lua_code)

# call a function from our Lua instance and store the value
let lua_value: LuaVal = callLuaFunc(L, "example_lua_function")

# stringifyLuaVal is a convenient function intended for echoing LuaVal
echo stringifyLuaVal(lua_value)

The ouput of this code would then be:

$ nim -r c example.nim

	"hi": "hello"

You can also pass an array of LuaVals to callLuaFunc. They will be used as arguments to the function.
(This can (possibly obviously) be used with LuaVals returned from callLuaFunc)

# example2.nim

import lua
import luna

const lua_code = """
function sum_values(a, b)
	return a + b


let lv1 = LuaVal(kind: LVNumber, n: 3)
let lv2 = LuaVal(kind: LVNumber, n: 4)
let lua_value: LuaVal = callLuaFunc(L, "sum_values", [lv1, lv2])

echo stingifyLuaVal(lua_value)


$ nim -r c example2.nim

Need help? Read Nimble
No tagged versions available
License: MIT

Project website Hosted docs