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();
	}
}
相关推荐
利来利往1 天前
【ai写代码】lua-判断表是否被修改
lua
陈天cjq1 天前
Redis 实用型限流与延时队列:从 Lua 固定/滑动窗口到 Streams 消费组(含脚本与压测)
redis·junit·lua
Warren981 天前
Lua 脚本在 Redis 中的应用
java·前端·网络·vue.js·redis·junit·lua
柯南二号2 天前
MacOS 系统计算机专业好用工具安装
开发语言·lua
神洛华2 天前
Lua语言程序设计2:函数、输入输出、控制结构
开发语言·lua
测试界清流7 天前
Postman接口测试入门
开发语言·lua
Volunteer Technology7 天前
Lua基础+Lua数据类型
开发语言·junit·lua
Volunteer Technology7 天前
openresty-lua-redis案例
redis·lua·openresty
WaterRun10 天前
开源项目luaToEXE: 将.lua封装为自带解释器无lua环境依赖的可执行文件工具
lua
William一直在路上11 天前
LUA脚本语言
开发语言·lua