Represents a Lua function.
LuaFunction sub-types luad.base.LuaObject through this reference.
Call this function and collect all return values as an array of luad.base.LuaObject references.
lua.doString(`function f(...) return ... end`); auto f = lua.get!LuaFunction("f"); LuaObject[] ret = f(1.2, "hello!", true); assert(ret[0].to!double() == 1.2); assert(ret[1].to!string() == "hello!"); assert(ret[2].to!bool());
Call this function.
T | expected return type. |
U args | list of arguments. |
lua.doString(`function ask(question) return 42 end`); auto ask = lua.get!LuaFunction("ask"); auto answer = ask.call!int("What's the answer to life, the universe and everything?"); assert(answer == 42);
Set a new environment for this function.
The environment of a function is the table used for looking up non-local (global) variables.
LuaTable env | new environment |
lua["foo"] = "bar"; auto func = lua.loadString(`return foo`); assert(func.call!string() == "bar"); auto env = lua.wrap(["foo": "test"]); func.setEnvironment(env); assert(func.call!string() == "test");
Dump this function as a binary chunk of Lua bytecode to the specified writer delegate. Multiple chunks may be produced to dump a single function.
bool delegate(in void[]) writer | delegate to forward writing calls to
If the delegate returns false for any of the chunks, the dump process ends, and the writer won't be called again. |