LuaD



enum  LuaErrorHandler: int;

Specify error handling scheme for LuaState.doString and LuaState.doFile.


No extra error handler.


Append a stack traceback to the error message.


class  LuaState;

Represents a Lua state instance.


this();

Create a new, empty Lua state. The standard library is not loaded.

If an uncaught error for any operation on this state causes a Lua panic for the underlying state, an exception of type luad.error.LuaErrorException is thrown.

See Also
LuaState.openLibs

this(lua_State* L);

Create a D wrapper for an existing Lua state.

The new LuaState object does not assume ownership of the state.

Parameters
lua_State* L state to wrap
Note:
The panic function is not changed - a Lua panic will not throw a D exception!
See Also
LuaState.setPanicHandler

pure nothrow @property @safe lua_State*  state();

The underlying lua_State pointer for interfacing with C.


static @trusted LuaState  fromPointer(lua_State* L);

Get the LuaState instance for a Lua state.

Parameters
lua_State* L Lua state
Returns
LuaState for the given lua_State*, or null if a LuaState is not currently attached to the state

@trusted void  openLibs();

Open the standard library.


@property @trusted LuaTable  globals();

The global table for this instance.


@property @trusted LuaTable  registry();

The registry table for this instance.


@trusted void  setPanicHandler(void function(LuaState, in char[]) onPanic);

Set a new panic handler.

Parameters
void function(LuaState, in char[]) onPanic new panic handler
Examples
auto L = luaL_newstate(); // found in luad.c.all
auto lua = new LuaState(L);

static void panic(LuaState lua, in char[] error)
{
	throw new LuaErrorException(error.idup);
}

lua.setPanicHandler(&panic);

@trusted LuaFunction  loadString(in char[] code);

Compile a string of Lua code.

Parameters
char[] code code to compile
Returns
Loaded code as a function.

@trusted LuaFunction  loadFile(in char[] path);

Compile a file of Lua code.

Parameters
char[] path path to file
Returns
Loaded code as a function.

@trusted LuaObject[]  doString(in char[] code, LuaErrorHandler handler = LuaErrorHandler.None);

Execute a string of Lua code.

Parameters
char[] code code to run
LuaErrorHandler handler error handling scheme
Returns
Any code return values
See Also
LuaErrorHandler

@trusted LuaObject[]  doFile(in char[] path, LuaErrorHandler handler = LuaErrorHandler.None);

Execute a file of Lua code.

Parameters
char[] path path to file
LuaErrorHandler handler error handling scheme
Returns
Any script return values
See Also
LuaErrorHandler

@trusted LuaTable  newTable()();

Create a new, empty table.

Returns
The new table

@trusted LuaTable  newTable()(uint narr, uint nrec);

Create a new, empty table with pre-allocated space for members.

Parameters
uint narr number of pre-allocated array slots
uint nrec number of pre-allocated non-array slots
Returns
The new table

@trusted LuaTable  newTable(Range)(Range range) if (isInputRange!Range);

Create a new table from an InputRange. If the element type of the range is Tuple!(T, U), then each element makes up a key-value pair, where T is the key and U is the value of the pair. For any other element type T, a table with sequential numeric keys is created (an array).

Parameters
Range range InputRange of key-value pairs or elements
Returns
The new table

@trusted T  wrap(T = LuaObject, U)(U value) if (is(T : LuaObject) || is(T == LuaDynamic));

Wrap a D value in a Lua reference.

Note that using this method is only necessary in certain situations, such as when you want to act on the reference before fully exposing it to Lua.

Parameters
T type of reference. Must be LuaObject, LuaTable, LuaFunction or LuaDynamic. Defaults to LuaObject.
U value D value to wrap
Returns
A Lua reference to value

@trusted LuaObject  registerType(T)();

Register a D class or struct with Lua.

This method exposes a type's constructors and static interface to Lua.

Parameters
T class or struct to register
Returns
Reference to the registered type in Lua

T  get(T, U...)(U args);

Same as calling globals.get with the same arguments.

See Also
luad.table.LuaTable.get

LuaObject  opIndex(T...)(T args);

Same as calling globals.get!LuaObject with the same arguments.

See Also
luad.table.LuaTable.opIndex

void  set(T, U)(T key, U value);

Same as calling globals.set with the same arguments.

See Also
luad.table.LuaTable.set

void  opIndexAssign(T, U...)(T value, U args);

Same as calling globals.opIndexAssign with the same arguments.

See Also
luad.table.LuaTable.opIndexAssign