using UnityEngine;
using System.Collections.Generic;
using LuaInterface;
public class AccessingLuaVariables : MonoBehaviour
{
private string luaScript =
@"
tab = {1,2,3,4,5}
tab.name = 'tab'
tab.map = {}
tab.map.name = 'map'
meta = {name = 'meta'}
setmetatable(tab,meta)
";
void Start ()
{
new LuaResLoader();
LuaState lua = new LuaState();
lua.Start();
lua.DoString(luaScript);
LuaTable tab = lua.GetTable("tab");
Debug.LogError(tab[1]); //1
Debug.LogError(tab["name"]); //tab
LuaTable map = tab["map"] as LuaTable;
Debug.LogError(map["name"]); //map
LuaTable meta = tab.GetMetaTable();
Debug.LogError(meta["name"]); //meta
table.Dispose();
lua.CheckTop();
lua.Dispose();
}
}