-
Notifications
You must be signed in to change notification settings - Fork 1
Tables
Kevin Zhao edited this page Jan 25, 2018
·
3 revisions
Tables can be created using the CreateTable
function:
var table = lua.CreateTable();
The table members can then be accessed/modified using the indexer. Since LuaTable
implements IDictionary<object, object>
, you can also use it exactly like a dictionary:
lua.DoString("table = { x = 6, y = 9, z = 10 }");
var table = (LuaTable)lua["table"];
Assert.Equal(3, table.Count);
Assert.True(table.Remove("x"));
Assert.False(table.ContainsKey("x"));
The Metatable
property allows you to get or set the metatable. This allows you to define custom operations on tables, essentially transforming them into full-fledged objects.
LuaTable
s support dynamic
access. You may access string keys directly:
dynamic table = lua.CreateTable();
table.x = 10;
table.x += 10;
If the table has the relevant metamethods (such as __add
for addition, __sub
for subtraction, etc), you may also perform operations:
dynamic table = ...
dynamic table2 = ...
dynamic sum = table + table2;