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();
	}
}
相关推荐
钟智强6 天前
CVE-2025-49844高危预警:Redis Lua脚本引擎UAF漏洞深度剖析与POC实战
数据库·redis·web安全·junit·lua
闲人编程6 天前
聚合管道与复杂查询
开发语言·oracle·lua·match·查询·聚合·lookup
会周易的程序员8 天前
cNetgate物联网网关内存数据表和数据视图模块架构
c语言·c++·物联网·架构·lua·iot
会周易的程序员9 天前
cNetgate插件架构设计详解 动态库 脚本二开lua, python, javascript
javascript·c++·python·物联网·lua·iot
白太岁12 天前
Redis:(3) Lua 与 Redis、基于连接池的 Facade 模式封装
数据库·c++·redis·lua·外观模式
Maguyusi17 天前
go 批量生成c++和lua proto文件
c++·golang·lua·protobuf
foxsen_xia17 天前
Kamailio通过Lua写路由
开发语言·lua·信息与通信
码农周20 天前
nginx + Lua 实现域名访问日志统计
nginx·lua
難釋懷21 天前
Lua脚本解决多条命令原子性问题
开发语言·lua
AI_567824 天前
Postman接口测试提速技巧:批量请求+智能断言实践
测试工具·lua·postman