public static bool writeJson(string sheetname, DataTable dataTable, string path) { string json = TableDataHandler.convertToJSON(dataTable); if (json == null) { return(false); } // 保存json文件 path += "\\" + sheetname + ".json"; UTF8Encoding utf8 = new UTF8Encoding(false); StreamWriter sw; using (sw = new StreamWriter(path, false, utf8)) { sw.Write(json); } sw.Close(); return(true); }
public static bool writeLua(string sheetname, DataTable dt, string path) { string json = TableDataHandler.convertToJSON(dt); if (json == null) { return(false); } Lua luaVM = new Lua(); luaVM.DoFile("./lua/main.lua"); object[] obj = luaVM.GetFunction("jsonToLua").Call(json); string strLua = ""; // 写表头 strLua += "--------------------------------------------------------\n"; strLua += "--info:" + sheetname + "\n"; strLua += "--author:" + Environment.UserName + "\n"; strLua += "--date:" + DateTime.Now + "\n"; strLua += "--------------------------------------------------------\n\nLua_Table=Lua_Table or {}\nLua_Table."; strLua += sheetname + "={\n"; strLua += obj[0]; strLua += "}return " + sheetname; // 保存lua文件 path += "\\" + sheetname + ".lua.txt"; UTF8Encoding utf8 = new UTF8Encoding(false); StreamWriter sw; using (sw = new StreamWriter(path, false, utf8)) { sw.Write(strLua); } sw.Close(); return(true); }