/// <summary> /// 生成 Lua 文件 /// </summary> /// <param name="path">路径</param> /// <param name="moduleName">模块名</param> /// <param name="folder">目录</param> public static void GeneratedLuaFile(string path, string moduleName, string className, LuaFolder folder) { string luaFileText = null; switch (folder) { case LuaFolder.Mdr: luaFileText = _setting.LuaMdrClassFile; break; case LuaFolder.Model: luaFileText = _setting.LuaModelClassFile; break; case LuaFolder.Service: luaFileText = _setting.LuaServicelClassFile; break; case LuaFolder.Vo: luaFileText = _setting.LuaVoClassFile; break; case LuaFolder.Controller: luaFileText = _setting.LuaCommandClassFile; break; } string instanceName = StringUtils.FirstToLower(className); luaFileText = string.Format(luaFileText, SystemUtils.GetSystemUserName(), TimeUtils.NowString()); LuaFolder moduleFolder = folder == LuaFolder.Mdr ? LuaFolder.View : folder; string modulePakerName = GetLuaPackerNameByPath(path + "/"); //模块包名 string packerName = GetLuaPackerNameByPath(path + Folder2Directory(moduleFolder)); //包名 luaFileText = StringUtils.ReplaceAll(luaFileText, _setting.MODULE_NAME, moduleName); luaFileText = StringUtils.ReplaceAll(luaFileText, _setting.Module_name, StringUtils.FirstToLower(moduleName)); luaFileText = StringUtils.ReplaceAll(luaFileText, _setting.MODULE_PACKER, modulePakerName); luaFileText = StringUtils.ReplaceAll(luaFileText, _setting.CLASS_PACKER, packerName); luaFileText = StringUtils.ReplaceAll(luaFileText, _setting.CLASS_NAME, className); luaFileText = StringUtils.ReplaceAll(luaFileText, _setting.INSTANCE_NAME, instanceName); luaFileText = StringUtils.ReplaceAll(luaFileText, "'", "\""); //Debug.Log(mdrFileText); string mdrFilePath = path + Folder2Directory(moduleFolder) + className + folder + ".lua"; if (!File.Exists(mdrFilePath)) { FileUtils.SaveTextFile(mdrFilePath, luaFileText); EditorUtility.DisplayDialog("提示", "生成 " + folder + " 文件成功", "确定"); } else { bool replace = EditorUtility.DisplayDialog("提示", "文件以及存在,是否替换?", "替换", "取消"); if (replace) { FileUtils.SaveTextFile(mdrFilePath, luaFileText); EditorUtility.DisplayDialog("提示", "生成 " + folder + " 文件成功", "确定"); } } }
//生成lua mvc line public static string GetSingletonLuaLine(string filePath, LuaFolder folder) { string fileName = Path.GetFileNameWithoutExtension(filePath); string viewName = fileName.Replace(folder.ToString(), ""); string packName = string.Format("Modules.{0}.{1}.{2}", viewName, folder.ToString(), fileName); return(string.Format(Format_Shingleton_Line, packName)); }
//生成lua mvc line public static string GetMdrLuaLine(string filePath, string moduleName, LuaFolder folder) { string fileName = Path.GetFileNameWithoutExtension(filePath); string viewName = fileName.Replace(folder.ToString(), ""); string packName = string.Format("Modules.{0}.View.{1}", moduleName, fileName); return(string.Format(Format_Mdr_Line, packName, viewName)); }
string GetLuaCodeLine(string filePath, string format, LuaFolder folder, bool isSingle) { string fileName = Path.GetFileNameWithoutExtension(filePath); string viewName = fileName.Replace(folder.ToString(), ""); string packName = string.Format("Modules.{0}.{1}.{2}", viewName, folder.ToString(), fileName); if (isSingle) { return(string.Format(format, packName)); } else { return(string.Format(format, packName, viewName)); } }
public object LoadFile(string file, Table globalContext) { if (file.StartsWith("module_")) { using (var stream = new LuaFolder().GetFile(file).Open(PCLExt.FileStorage.FileAccess.Read)) using (var reader = new StreamReader(stream)) return(reader.ReadToEnd()); } else { using (var stream = Modules.GetFile(file).Open(PCLExt.FileStorage.FileAccess.Read)) using (var reader = new StreamReader(stream)) return(reader.ReadToEnd()); } }
public static LuaFileStatus GetFileStatus(string moduleDirPath, LuaFolder folder, string fileName = null) { LuaFolder moduleFolder = folder == LuaFolder.Mdr ? LuaFolder.View : folder; moduleDirPath = moduleDirPath + Folder2Directory(moduleFolder); if (Directory.Exists(moduleDirPath)) { string[] lusFiles = Directory.GetFiles(moduleDirPath, "*.lua"); if (lusFiles.Length == 0) { return(LuaFileStatus.Folder_Only); } else { bool hasFolderFile = false; for (int i = 0; i < lusFiles.Length; i++) { if (lusFiles[i].LastIndexOf(folder.ToString()) != -1) { hasFolderFile = true; break; } } if (fileName != null) { for (int i = 0; i < lusFiles.Length; i++) { var tempFileName = lusFiles[i].Replace(folder.ToString(), ""); tempFileName = Path.GetFileNameWithoutExtension(tempFileName); if (tempFileName == fileName) { return(LuaFileStatus.Folder_And_TagLuaFile); } } } // if (hasFolderFile) return(LuaFileStatus.Folder_And_LuaFile); // else // return LuaFileStatus.Nothing; } } return(LuaFileStatus.Nothing); }
void EditFolder(LuaModuleInfo moduleInfo, LuaFolder folder) { string folderPath = moduleInfo.moduleDirPath + ToLuaGenerater.Folder2Directory(folder); LuaFileStatus status = ToLuaGenerater.GetFileStatus(moduleInfo.moduleDirPath, folder); switch (status) { case LuaFileStatus.Nothing: if (GUILayout.Button("生成 " + folder + " 文件夹")) { ToLuaGenerater.GeneratedFolder(folderPath); } break; case LuaFileStatus.Folder_Only: if (folder == LuaFolder.Vo) { AddVoFile(moduleInfo); } else if (folder == LuaFolder.Controller) { AddCommandFile(moduleInfo); } else if (GUILayout.Button("生成 " + folder + ".lua 文件")) { ToLuaGenerater.GeneratedLuaFile(moduleInfo.moduleDirPath, moduleInfo.moduleName, moduleInfo.moduleName, folder); } break; case LuaFileStatus.Folder_And_LuaFile: if (folder == LuaFolder.Vo) { AddVoFile(moduleInfo); } else if (folder == LuaFolder.Controller) { AddCommandFile(moduleInfo); } else { EditorGUILayout.LabelField(moduleInfo.moduleName + folder + ".lua 文件已经生成"); } break; } }
private Table CompileFile(string path) { var modules = CoreModules.Preset_SoftSandbox; IFolder folder = new LuaFolder(); var dirs = path.Split(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar).Reverse().Skip(1).Reverse(); foreach (var dir in dirs) { folder = folder.CreateFolderAsync(dir, CreationCollisionOption.OpenIfExists).Result; } var file = System.IO.Path.GetFileName(path); var text = folder.GetFileAsync(file).Result.ReadAllTextAsync().Result; var table = AddDefaultFunctions(new Table(Script).RegisterCoreModules(modules)); Script.DoString(text, table); return(table); }
private Table GetFiles(string path) { IFolder folder = new LuaFolder(); var dirs = path.Split(System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar).Reverse().Skip(1).Reverse(); foreach (var dir in dirs) { folder = folder.CreateFolder(dir, CreationCollisionOption.OpenIfExists); } var files = folder.GetFilesAsync().Result; var table = new Table(Script); foreach (var file in files) { table.Append(DynValue.NewString(file.Name)); } //table["files"] = files.Select(file => file.Name).ToList(); return(table); }
public static string Folder2Directory(LuaFolder folder) { return("/" + folder.ToString() + "/"); }