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 天前
Lua 安装使用教程
开发语言·lua
Accpdaiyekun1 天前
C# 操作mongodb 多次查询快还是使用管道查询速度快
mongodb·c#·lua
快下雨了L2 天前
Lua现学现卖
开发语言·lua
WIN赢11 天前
PostMan使用
测试工具·lua·postman
多多*11 天前
计算机网络期末 网络基础概述
运维·服务器·网络·数据库·计算机网络·oracle·lua
11 天前
Lua复习之何为闭包
开发语言·unity·游戏引擎·lua·交互
码上库利南11 天前
详解Redis的LUA脚本、管道 (Pipelining)、事务事务 (Transactions)
数据库·redis·lua
RPGMZ12 天前
RPGMZ 游戏引擎如何与lua进行互相调用 初探
开发语言·javascript·游戏引擎·lua·rpgmz
Hello.Reader13 天前
Lua 事务双写、RedisGears 异步双写、零停机索引迁移与容量预估
开发语言·lua
虾球xz13 天前
CppCon 2017 学习:Howling at the Moon: Lua for C++ Programmers
开发语言·c++·学习·lua