LuaD



struct  LuaFunction;

Represents a Lua function.


LuaObject  object;

LuaFunction sub-types luad.base.LuaObject through this reference.


LuaObject[]  opCall(U...)(U args);

Call this function and collect all return values as an array of luad.base.LuaObject references.

Examples
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());

T  call(T = void, U...)(U args);

Call this function.

Parameters
T expected return type.
U args list of arguments.
Returns
Return value of type T, or nothing if T was unspecified. See luad.conversions.functions for how to catch multiple return values.
Examples
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);

void  setEnvironment(ref LuaTable env);

Set a new environment for this function.

The environment of a function is the table used for looking up non-local (global) variables.

Parameters
LuaTable env new environment
Examples
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");

bool  dump(scope bool delegate(in void[]) writer);

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.

Parameters
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.