LuaD

Internal module for pushing and getting functions and delegates.

LuaD allows for pushing of all D function or delegate types with return type and parameter types compatible with LuaD (see luad.stack).

For a fixed number of multiple return values, return a std.typecons.Tuple or a static array. For a variable number of return values, return LuaVariableReturn.

As a special case for const(char)[] parameter types in functions pushed to Lua, no copy of the string is made when called; take care not to escape such references, they are effectively scope parameters. When a copy is desired, use char[] or string, or dup or idup the string manually.

If a function with the lua_CFunction signature is encountered, it is pushed directly with no inserted conversions or overhead.

Typesafe varargs is supported when pushing functions to Lua, but as of DMD 2.054, compiler bugs prevent getting delegates with varargs from Lua (use luad.lfunction.LuaFunction instead).


T  getFunction(T)(lua_State* L, int idx) if (is(T == delegate));

Currently this function allocates a reference in the registry that is never deleted, one for each call... see code comments


struct  LuaVariableReturn(Range) if (isInputRange!Range);

Type for efficiently returning a variable number of return values from a function.

Use variableReturn to instantiate it.

Parameters
Range any input range

alias  WrappedType = Range;

The type of the wrapped input range.


Range  returnValues;

The wrapped input range.


LuaVariableReturn!Range  variableReturn(Range)(Range returnValues) if (isInputRange!Range);

Create a LuaVariableReturn object for efficiently returning a variable number of values from a function.

Parameters
Range returnValues any input range
Example:
	LuaVariableReturn!(uint[]) makeList(uint n)
	{
		uint[] list;

		foreach(i; 1 .. n + 1)
		{
			list ~= i;
		}

		return variableReturn(list);
	}

	lua["makeList"] = &makeList;

	lua.doString(`
		local one, two, three, four = makeList(4)
		assert(one == 1)
		assert(two == 2)
		assert(three == 3)
		assert(four == 4)
	`);