No description
Find a file
small f(x) 75ece08363
Merge pull request #2 from treeform/patch-1
Fix to luna.nimble, name is not a valid key.
2019-03-08 18:09:19 +09:00
luna.nim Renamed nimble package 2016-07-10 15:11:17 -07:00
luna.nimble Fix to luna.nimble, name is not a valid key. 2018-02-27 10:42:33 -08:00
README.md added readme 2016-07-03 20:32:16 -07:00

#luna.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

# example.nim

import lua
import luna

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

# set up Lua state like normal
let L = newstate()
openlibs(L)
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
end
"""

...

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)

output:

$ nim -r c example2.nim
...

7