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();
	}
}
相关推荐
上海合宙LuatOS1 天前
LuatOS扩展库API——【extp】触摸控制
嵌入式硬件·物联网·lua·luatos
上海合宙LuatOS1 天前
LuatOS扩展库API——【exvib】震动检测
开发语言·物联网·lua·luatos
TechExplorer3651 天前
Postman 9.12 安装、汉化、禁用更新
测试工具·lua·postman
liulilittle2 天前
Lua 浮点数比较
开发语言·junit·lua
rannn_1112 天前
【Redis|高级篇2】多级缓存|JVM进程缓存、Lua语法、多级缓存实现(OpenResty)、缓存同步(Canal)
java·redis·分布式·后端·缓存·lua·openresty
VT LI4 天前
Lua 源码执行流程全解析:词法分析、语法分析、字节码生成、虚拟机执行与垃圾回收
java·开发语言·lua
历程里程碑5 天前
二叉树---二叉树的中序遍历
java·大数据·开发语言·elasticsearch·链表·搜索引擎·lua
上海合宙LuatOS6 天前
LuatOS扩展库API——【exremotefile】远程文件管理系统
物联网·lua·luatos
上海合宙LuatOS6 天前
LuatOS扩展库API——【exremotecam】网络摄像头控制
开发语言·网络·物联网·lua·luatos
专吃海绵宝宝菠萝屋的派大星6 天前
使用postman测试自己编写的mcp服务
测试工具·lua·postman