luad.stack

This internal module, with the help of the luad.conversions package, takes care of converting between D and Lua types.

The conversion rules are as follows, where conversion goes both ways:

boolean
bool
number
lua_Integer (default int)
lua_Number (default double)
string
string, const(char)[], char[]
const(char)*
char
immutable(void)[], const(void)[], void[] (binary data)
table
associative arrays (see $(DPMODULE2 conversions,assocarrays))
arrays (see $(DPMODULE2 conversions,arrays))
structs (see $(DPMODULE2 conversions,structs))
$(DPREF table,LuaTable)
function (see $(DPMODULE2 conversions,functions))
function pointers
delegates
$(DPREF lfunction,LuaFunction)
userdata
classes (see $(DPMODULE2 conversions,classes))
nil
the special identifier nil
null class references
any of the above
$(DPREF base,LuaObject)
$(DPREF dynamic,LuaDynamic)
Algebraic, when given a compatible value (see $(DPMODULE2 conversions,variant))

The conversions are checked in the specified order. For example, even though bool is implicitly convertible to lua_Integer, it will be converted to a boolean because boolean has precedence.

wchar and dchar are explicitly disallowed. Lua strings consist of 8-bit characters, if you want to push UTF-16 or UTF-32 strings, convert to UTF-8 first.

Additionally, the following types are pushable to Lua, but can't be retrieved back:

function
lua_CFunction

Members

Functions

callWithRet
T callWithRet(lua_State* L, int nargs)

Call a Lua function and handle its return values.

getArgument
auto getArgument(lua_State* L, int idx)

Get a function argument from the stack.

getValue
T getValue(lua_State* L, int idx)

Get a value of any type from the stack.

popReturnValues
T popReturnValues(lua_State* L, size_t nret)

Pop return values from stack. Defaults to popValue, but has special handling for $(DPREF2 conversions, functions, LuaVariableReturn), $(STDREF typecons, Tuple), static arrays and void.

popStack
T[] popStack(lua_State* L, size_t n)

Pop a number of elements from the stack.

popTuple
T popTuple(lua_State* L)

Pops a $(STDREF typecons, Tuple) from the values at the top of the stack.

popValue
T popValue(lua_State* L)

Same as calling getValue!(T, typeMismatchHandler)(L, -1), then popping one value from the stack.

printStack
void printStack(lua_State* L)

Print the Lua stack to stdout.

pushReturnValues
int pushReturnValues(lua_State* L, T value)

Push return values to the stack. Defaults to pushValue, but has special handling for $(DPREF2 conversions, functions, LuaVariableReturn), $(STDREF typecons, Tuple) and static arrays.

pushTuple
void pushTuple(lua_State* L, T tup)

Pushes all the values in a $(STDREF typecons, Tuple) to the stack.

pushValue
void pushValue(lua_State* L, T value)

Push a value of any type to the stack.

Templates

isVariableReturnType
template isVariableReturnType(T : LuaVariableReturn!U, U)
Undocumented in source.
isVariableReturnType
template isVariableReturnType(T)
Undocumented in source.
isVoidArray
template isVoidArray(T)
Undocumented in source.
luaTypeOf
template luaTypeOf(T)

Get the associated Lua type for T.

returnTypeSize
template returnTypeSize(T)

Used for getting a suitable nresults argument to lua_call or lua_pcall.

Meta