LuaInterface: add a table to the script scope
Posted
by user93422
on Stack Overflow
See other posts from Stack Overflow
or by user93422
Published on 2010-06-11T15:44:36Z
Indexed on
2010/06/16
4:42 UTC
Read the original article
Hit count: 226
lua
|luainterface
Question: how can I insert a table from C# into 'LuaInterface' script scope using a C# object (preferably anonymous type)?
/// I want to do this, but it does not work
/// (complains that 'test' is userdata and not table
/// when I pass it to pairs() in the script)
//lua["test"] = new { A = 1, B = 2 };
/// another option
/// but building this string is a PITA (actual string is nested and long).
lua.DoString("test = { A = 1, B = 2 }");
// So I have to do this
lua.NewTable("test");
((LuaTable) lua["test"])["A"] = 1;
((LuaTable) lua["test"])["B"] = 2;
lua.DoString("for k,v in pairs(test) do print(k..': '..v) end");
© Stack Overflow or respective owner