把Lua里的Table转换为 字典 或 List
C#
using System.Collections.Generic;
using UnityEngine;
using XLua;
public class CsCallLua : MonoBehaviour {
void Start () {
var luaenv = new XLua.LuaEnv();
luaenv.DoString("require 'CsCallLua'");
// table to dic、list
//to dic
Dictionary<string, object> dic = luaenv.Global.Get<Dictionary<string, object>>("teather");
foreach (var item in dic)
{
print("key:" + item.Key + " value:" + item.Value);
}
//to list
List<object> list = luaenv.Global.Get<List<object>>("teather");
foreach (var item in list)
{
print("List:"+item);
}
luaenv.Dispose();
}
}
CsCallLua.lua
teather = {
--字典
name = "cjh",
age = 18,
isHandsome = true,
--list
3,4,5
}
字典
List