Exemple #1
0
        protected override LuaValue _OnGetLuaValue()
        {
            LuaMap mp = new LuaMap();

            mp.init(false, ExportSheetBin.ROW_MAX_ELEMENT);
            return(mp);
        }
Exemple #2
0
        public static OptData getExportContent(ExcelToMapData v_data, int v_optCode,
                                               string[] rootPath, string fileName)
        {
            OptData       rtn = new OptData();
            StringBuilder sb  = new StringBuilder();

            try
            {
                LuaMap root = GetLuaTable(v_data._data, v_data.IsSingleKey);
                sb.Append("--[[\r\n");
                sb.AppendFormat("output from excel {0}\r\n", v_data.excelName);
                v_data.opt_note(sb, "note");
                sb.Append("\r\n");
                sb.Append("colums:\r\n");
                v_data.opt_colum_notes(sb, v_optCode);
                sb.Append("\r\n");
                sb.Append("primary key:\r\n");
                for (int i = 0; i < v_data.sheet_bins.Count; i++)
                {
                    sb.AppendFormat("#{0} [{1}]: ", i, v_data.sheet_bins[i].sheetName);
                    sb.Append(string.Join(",", v_data.sheet_bins[i].indexData.pmKey));
                    sb.Append("\r\n");
                }
                sb.Append("]]\r\n");

                sb.Append("local _T = LangUtil.Language\r\n");

                if (v_data.IsDataPersistence)
                {
                    sb.AppendFormat("if ddt[\"{0}\"] ~= nil then\r\n\treturn ddt[\"{0}\"]\r\nend\r\n", v_data.className);
                    sb.Append("local data = ");
                    root.outputValue(sb, 0);
                    sb.AppendLine();
                    sb.AppendFormat("ddt[\"{0}\"] = data\r\n", v_data.className);
                    //sb.Append("SetLooseReadonly(data)\r\n");
                    sb.Append("return data");
                }
                else
                {
                    sb.Append("return");
                    root.outputValue(sb, 0);
                }
            }
            catch (Exception ex)
            {
                rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString());
            }

            rtn.content = sb.ToString();

            for (int i = 0; i < rootPath.Length; i++)
            {
                string opt_path = rootPath[i] + fileName;
                File.WriteAllText(opt_path, rtn.content);
            }

            return(rtn);
            //sb.Append(string.Format("\r\nreturn {0}", curIndex.className));
        }
Exemple #3
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);
        }
Exemple #4
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;
                }
            }
        }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
0
        public static OptData getExportContent(ExcelToMapData v_data, int v_optCode)
        {
            OptData       rtn = new OptData();
            StringBuilder sb  = new StringBuilder();

            try
            {
                LuaMap root = GetLuaTable(v_data._data);
                sb.Append("--[[\r\n");
                v_data.opt_note(sb, "note");
                sb.Append("\r\n");
                sb.Append("colums:\r\n");
                v_data.opt_colum_notes(sb);
                sb.Append("\r\n");
                sb.Append("primary key:\r\n");
                for (int i = 0; i < v_data.sheet_bins.Count; i++)
                {
                    sb.AppendFormat("#{0} [{1}]: ", i, v_data.sheet_bins[i].sheetName);
                    sb.Append(string.Join(",", v_data.sheet_bins[i].indexData.pmKey));
                    sb.Append("\r\n");
                }
                sb.Append("]]\r\n");

                if (v_data.IsDataPersistence)
                {
                    sb.AppendFormat("if ddt[v_data.className] ~= nil then\r\n\treturn {0}\r\nend\r\n", v_data.className);
                    sb.AppendFormat("local {0} = ", v_data.className);
                    root.outputValue(sb, 0);
                    sb.AppendLine();
                    sb.AppendFormat("ddt[v_data.className] = {0}\r\n", v_data.className);
                    sb.AppendFormat("SetLooseReadonly({0})\r\n", v_data.className);
                    sb.AppendFormat("return {0}", v_data.className);
                }
                else
                {
                    sb.Append("return");
                    root.outputValue(sb, 0);
                }
            }
            catch (Exception ex)
            {
                rtn.errList.Add("导出基础数据时出现错误,错误信息为:\r\n" + ex.ToString());
            }
            rtn.content = sb.ToString();
            return(rtn);
            //sb.Append(string.Format("\r\nreturn {0}", curIndex.className));
        }