1. 程式人生 > >c#解析lua-Table型別

c#解析lua-Table型別

                LuaInterface.LuaTable ob = XLuaManager.Inst.Call("CombineDef.GetCombineItems", mItemType, mItemId)[0] as LuaInterface.LuaTable;
                
                XTools.Log("**** --- {0}", ob.Values.Count); //ob.Values[0];
//                 IEnumerator itr = ob.Keys.GetEnumerator();
//                 while(itr.MoveNext())
//                 {
//                     //KeyValuePair<XSkillType, int> pair = (KeyValuePair<XSkillType, int>)itr.Current;
//                     string nnn = (string)itr.Current;
//                     XTools.Log("---{0}", nnn);
//                 }
                IEnumerator itr = ob.Values.GetEnumerator();
                int i = 0;
                while(itr.MoveNext())
                {
                    LuaInterface.LuaTable tb = itr.Current as LuaInterface.LuaTable;
                    IEnumerator it2 = tb.Values.GetEnumerator();
                    XTools.Log("=={0}---key{1}", tb.Values.Count, i);
                    int j = 0;
                    while (it2.MoveNext())
                    {
                        //KeyValuePair<int, int> pair = (KeyValuePair<int, int>)it2.Current;
                        XTools.Log("---{0},{1}--------key:{2}{3}", it2.Current.GetType().ToString(), (double)it2.Current, i, ++j);
                    }
                    i++;
                }



 LuaInterface.LuaTable ob = XLuaManager.Inst.Call("CombineDef.GetCombineItems", mItemType, mItemId)[0] as string;

http://book.luaer.cn/

lua定義結構體:

Npc.BubbleProperty = 
{
Silence = { Weight = 200 },-- 沉默
Task = { Weight = 50, nIndex = "Task" },-- 普通泡泡
Normal = { Weight = 50, nIndex = "Normal" },-- 任務泡泡
};


local tbPos =
{
[1] = { nX = nX,nY = nY};
[2] = { nX = nX - nSpan,nY = nY};
[3] = { nX = nX + nSpan,nY = nY};
[4] = { nX = nX,nY = nY - nSpan };
[5] = { nX = nX,nY = nY + nSpan };
[6] = { nX = nX - nSpan,nY = nY + nSpan };
[7] = { nX = nX + nSpan,nY = nY + nSpan };
[8] = { nX = nX + nSpan,nY = nY - nSpan };
[9] = { nX = nX - nSpan,nY = nY - nSpan };
};