コード例 #1
0
        protected override LuaValue _OnGetLuaValue()
        {
            LuaMap mp = new LuaMap();

            mp.init(false, ExportSheetBin.ROW_MAX_ELEMENT);
            return(mp);
        }
コード例 #2
0
        public static LuaMap GetLuaTable(ExcelMapData v_root, bool v_bSingleKey = false)
        {
            LuaMap luaRoot = new LuaMap();

            luaRoot.init(true, ExportSheetBin.ROW_MAX_ELEMENT);
            _translate(v_root, luaRoot, v_bSingleKey);
            return(luaRoot);
        }
コード例 #3
0
        private static void _translate(ExcelMapData v_src, LuaTable v_dst, bool v_bSingleKey = false)
        {
            List <KeyValue <ExcelMapData> > childDatas = v_src.GetKeyValues();

            for (int i = 0; i < childDatas.Count; i++)
            {
                KeyValue <ExcelMapData> child = childDatas[i];
                Key          key  = child.key;
                ExcelMapData data = child.val;
                switch (data.Type)
                {
                case EExcelMapDataType.indexMap:
                    LuaMap indexMap = new LuaMap();
                    indexMap.init(true, ExportSheetBin.ROW_MAX_ELEMENT);
                    v_dst.addData(key, indexMap);
                    _translate(data, indexMap, v_bSingleKey);
                    indexMap.Note = data.Note;
                    break;

                case EExcelMapDataType.rowData:
                    LuaMap rowData = new LuaMap();
                    rowData.init(false, ExportSheetBin.ROW_MAX_ELEMENT);
                    rowData.Single_value_hide_key = v_bSingleKey;
                    v_dst.addData(key, rowData);
                    _translate(data, rowData, v_bSingleKey);
                    rowData.Note = data.Note;
                    break;

                case EExcelMapDataType.cellTable:
                    LuaTable cellTable;
                    if (data.IsArray)
                    {
                        cellTable = new LuaArray();
                        ((LuaArray)cellTable).init(false, true, ExportSheetBin.ROW_MAX_ELEMENT);
                    }
                    else
                    {
                        cellTable = new LuaMap();
                        ((LuaMap)cellTable).init(false, ExportSheetBin.ROW_MAX_ELEMENT);
                    }
                    v_dst.addData(key, cellTable);
                    _translate(data, cellTable);
                    cellTable.Note = data.Note;
                    break;

                case EExcelMapDataType.cellData:
                    LuaValue leafVal = data.LeafVal.GetLuaValue();
                    v_dst.addData(key, leafVal);
                    leafVal.Note = data.Note;
                    break;
                }
            }
        }
コード例 #4
0
        protected override bool _OnInit(string v_strCellVal)
        {
            _key = v_strCellVal;
            Lua.Lua lua_state = LuaState.Get_Instenct();
            object  lua_data  = null;
            var     tmprst    = lua_state.DoString("return " + v_strCellVal);

            if (tmprst == null)
            {
                Debug.ExcelError("return " + v_strCellVal + " is nil");
                return(false);
            }
            lua_data = tmprst[0];
            if (lua_data == null)
            {
                _luaval = new LuaNil();
                return(true);
            }
            else if (lua_data is Lua.LuaTable)
            {
                Lua.LuaTable table = lua_data as Lua.LuaTable;
                LuaMap       map   = new LuaMap();
                map.init(_isStretch, ExportSheetBin.ROW_MAX_ELEMENT);
                if (!fill_luatable(map, table))
                {
                    _luaval = new LuaNil();
                    return(false);
                }
                _luaval = map;
                return(true);
            }
            else if (lua_data is double)
            {
                _luaval = new LuaDouble(Convert.ToDouble(lua_data));
                return(true);
            }
            else if (lua_data is string)
            {
                _luaval = new LuaString(Convert.ToString(lua_data));
                return(true);
            }
            else if (lua_data is bool)
            {
                _luaval = new LuaBoolean(Convert.ToBoolean(lua_data));
                return(true);
            }

            return(false);
        }
コード例 #5
0
        protected bool fill_luatable(LuaMap v_map, Lua.LuaTable v_luatable)
        {
            foreach (KeyValuePair <object, object> i in v_luatable)
            {
                LuaValue val = null;
                if (i.Value is Lua.LuaTable)
                {
                    LuaMap newTable = new LuaMap();
                    newTable.init(_isStretch, ExportSheetBin.ROW_MAX_ELEMENT);
                    fill_luatable(newTable, (Lua.LuaTable)i.Value);
                    val = newTable;
                }
                else
                {
                    if (i.Value is double)
                    {
                        val = new LuaDouble(Convert.ToDouble(i.Value));
                    }
                    else if (i.Value is string)
                    {
                        val = new LuaString(Convert.ToString(i.Value));
                    }
                    else if (i.Value is bool)
                    {
                        val = new LuaBoolean(Convert.ToBoolean(i.Value));
                    }
                    else if (i.Value == null)
                    {
                        val = new LuaNil();
                    }
                    else
                    {
                        Debug.Exception("出现了无法识别的luavalue,键是{0}", i.Key);
                    }
                }

                if (i.Key is int || i.Key is double)
                {
                    v_map.addData(Convert.ToInt32(i.Key), val);
                }
                else if (i.Key is string)
                {
                    v_map.addData(Convert.ToString(i.Key), val);
                }
            }
            return(true);
        }