C#调用TableByDicList

把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

发布了205 篇原创文章 · 获赞 8 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/cuijiahao/article/details/103905152
今日推荐