Lua之Lua源文件批量转换为luac字节码文件

准备的工具:luac.exe CSDNhttps://mp.csdn.net/mp_download/manage/download/UpDetailed

Unity版:

复制代码
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

public static class Batch_LuaToLuac
{
	[UnityEditor.MenuItem("Tools/LuaToLuac")]
	static void ToLuac()
	{
		//准备进程信息
		string luacExe = "luac53.exe";  //luac.exe工具文件名
		string luacExe_Dir = @"D:\workspace\Test\T4\PureProject_Develop\Development2020\Tools\Lua"; //luac.exe工具路径
		string luacExe_fullpath = Path.Combine(luacExe_Dir, luacExe);   //luac.exe工具完整路径

		var processStartInfo = new System.Diagnostics.ProcessStartInfo();
		processStartInfo.FileName = luacExe_fullpath;
		processStartInfo.UseShellExecute = true;
		processStartInfo.ErrorDialog = true;
		processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

		void DoExe(string srcFile, string outFile)
		{
			//执行转换进程
			try
			{
				string args = string.Format("-o {0} {1}", outFile, srcFile);
				processStartInfo.Arguments = args;

				var process = System.Diagnostics.Process.Start(processStartInfo);
				process.WaitForExit();
			}
			catch (Exception ex)
			{
				Debug.LogError(ex.ToString());
			}

		}

		//lua源文件路径
		var luaFileDir = Application.dataPath + "/LuaSource";
		//生成的luac文件路径
		var outPutDir = Path.Combine(luaFileDir, "luac");
		if (Directory.Exists(outPutDir)) Directory.Delete(outPutDir, true);
		Directory.CreateDirectory(outPutDir);

		var files = Directory.GetFiles(luaFileDir, "*.lua", SearchOption.TopDirectoryOnly);
		foreach (var file in files)
		{
			if (file.Contains(".meta")) { continue; }
			var outFile = Path.Combine(outPutDir, Path.GetFileNameWithoutExtension(file) + ".luac");
			DoExe(file, outFile);
		}

		AssetDatabase.Refresh();
	}
}
相关推荐
@大迁世界8 小时前
6 款轻量级 CLI 工具,取代了我臃肿的开发软件
开发语言·lua
无籽西瓜a9 小时前
Docker 环境下 Redis Lua 脚本部署与执行
redis·docker·lua
想做后端的前端1 天前
Lua的元表和元方法
开发语言·junit·lua
呆子也有梦1 天前
思考篇:积分是存成道具还是直接存数值?——ET/Skynet 框架下,从架构权衡到代码实现全解析
游戏·架构·c#·lua
liulilittle1 天前
Lua中检测32位序号环绕的方法
junit·单元测试·lua
历程里程碑2 天前
链表-----
数据结构·线性代数·算法·链表·矩阵·lua·perl
星空露珠2 天前
迷你世界UGC3.0脚本Wiki角色模块管理接口 Actor
开发语言·数据库·算法·游戏·lua
利来利往2 天前
【lua】loop is executed at most oncelua-analyzer(512)
lua
星空露珠2 天前
迷你世界UGC3.0脚本Wiki对象模块管理接口 GameObject
开发语言·数据库·算法·游戏·lua
或与且与或非2 天前
Redis-Lua脚本调试教程
数据库·redis·lua