<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sheenidgs137</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sheenidgs137"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Sheenidgs137"/>
	<updated>2026-04-20T01:56:07Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=Lua_compilation_API&amp;diff=75685</id>
		<title>Lua compilation API</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=Lua_compilation_API&amp;diff=75685"/>
		<updated>2022-11-21T02:52:07Z</updated>

		<summary type="html">&lt;p&gt;Sheenidgs137: Fixed typo API Parameters from luasource to obfuscate&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page is a guide for Lua compilation API.&lt;br /&gt;
&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
POST &amp;quot;http://luac.mtasa.com/index.php&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Parameters==&lt;br /&gt;
*'''luasource:''' type '''file''' the file content&lt;br /&gt;
*'''compile:''' type '''value''' set to 1 to enable compilation&lt;br /&gt;
*'''debug:''' type '''value''' set to 1 to enable debug information&lt;br /&gt;
*'''obfuscate:''' type '''value'''&lt;br /&gt;
**Set to 1 to enable some obfuscation&lt;br /&gt;
**Set to 2 to enable more obfuscation (From 1.5.2-9.07903)&lt;br /&gt;
**Set to 3 to enable even more obfuscation (From 1.5.6-9.18728)&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
===Linux example using curl===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
FROM=&amp;quot;example.lua&amp;quot;&lt;br /&gt;
TO=&amp;quot;compiled.lua&amp;quot;&lt;br /&gt;
curl -s -X POST -F compile=1 -F debug=0 -F obfuscate=3 -F luasource=@$FROM http://luac.mtasa.com/ &amp;gt; $TO&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
===Linux example using luac replacement===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
luac_mta -e3 -o compiled.lua example.lua&lt;br /&gt;
if [ $? -ne 0 ]; then&lt;br /&gt;
   echo &amp;quot;Error&amp;quot;&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Need luac_mta (R13 2019-07-12) for [//luac.mtasa.com/files/linux/x86/luac_mta Linux 32 bit] or [//luac.mtasa.com/files/linux/x64/luac_mta Linux 64 bit]&lt;br /&gt;
&lt;br /&gt;
===Windows batch file example using curl===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;batch&amp;quot;&amp;gt;&lt;br /&gt;
set FROM=&amp;quot;example.lua&amp;quot;&lt;br /&gt;
set TO=&amp;quot;compiled.lua&amp;quot;&lt;br /&gt;
curl.exe -s -X POST -F compile=1 -F debug=0 -F obfuscate=3 -F luasource=@%FROM% http://luac.mtasa.com/ &amp;gt; %TO%&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Get [//luac.mtasa.com/files/windows/x86/curl.exe curl.exe]&amp;lt;/br&amp;gt;&lt;br /&gt;
(Original from http://curl.haxx.se/download.html)&lt;br /&gt;
&lt;br /&gt;
===Windows example using luac.exe replacement===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;batch&amp;quot;&amp;gt;&lt;br /&gt;
luac_mta.exe -e3 -o compiled.lua example.lua&lt;br /&gt;
IF NOT ERRORLEVEL 1 goto lp1&lt;br /&gt;
   echo &amp;quot;Error&amp;quot;&lt;br /&gt;
:lp1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Get [//luac.mtasa.com/files/windows/x86/luac_mta.exe luac_mta.exe] (R12 2019-07-12) '''only x86'''&lt;br /&gt;
===Lua example===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- This example allows you to compile all resource scripts by using /compilelua command.&lt;br /&gt;
&lt;br /&gt;
local compileEnabled = 1&lt;br /&gt;
local debugLevel = 0&lt;br /&gt;
local obfuscateLevel = 3&lt;br /&gt;
local apiCodes = {&lt;br /&gt;
	[&amp;quot;ERROR Nothing to do - Please select compile and/or obfuscate&amp;quot;] = true,&lt;br /&gt;
	[&amp;quot;ERROR Could not compile file&amp;quot;] = true,&lt;br /&gt;
	[&amp;quot;ERROR Could not read file&amp;quot;] = true,&lt;br /&gt;
	[&amp;quot;ERROR Already compiled&amp;quot;] = true,&lt;br /&gt;
	[&amp;quot;ERROR Already encrypted&amp;quot;] = true,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function loadScriptsFromMeta()&lt;br /&gt;
	local metaFile = xmlLoadFile(&amp;quot;meta.xml&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
	if not metaFile then&lt;br /&gt;
		outputDebugString(&amp;quot;[LUAC]: Failed to load scripts from meta.&amp;quot;, 4, 255, 127, 0)&lt;br /&gt;
&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local metaChildren = xmlNodeGetChildren(metaFile)&lt;br /&gt;
	local scriptsTable = {}&lt;br /&gt;
&lt;br /&gt;
	for nodeID = 1, #metaChildren do&lt;br /&gt;
		local metaNode = metaChildren[nodeID]&lt;br /&gt;
		local fileSrc = xmlNodeGetAttribute(metaNode, &amp;quot;src&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
		if fileSrc then&lt;br /&gt;
			local luaScript = stringFind(fileSrc, &amp;quot;.lua&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
			if luaScript then&lt;br /&gt;
				scriptsTable[#scriptsTable + 1] = fileSrc&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	xmlUnloadFile(metaFile)&lt;br /&gt;
&lt;br /&gt;
	return scriptsTable&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function loadResourceScript(pPath)&lt;br /&gt;
	local scriptExists = fileExists(pPath)&lt;br /&gt;
&lt;br /&gt;
	if not scriptExists then&lt;br /&gt;
		outputDebugString(&amp;quot;[LUAC]: '&amp;quot;..pPath..&amp;quot;' doesn't exists.&amp;quot;, 4, 255, 127, 0)&lt;br /&gt;
&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local scriptHandler = fileOpen(pPath)&lt;br /&gt;
&lt;br /&gt;
	if not scriptHandler then&lt;br /&gt;
		outputDebugString(&amp;quot;[LUAC]: '&amp;quot;..pPath..&amp;quot;' failed to open.&amp;quot;, 4, 255, 127, 0)&lt;br /&gt;
&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local scriptSize = fileGetSize(scriptHandler)&lt;br /&gt;
	local scriptRaw = fileRead(scriptHandler, scriptSize)&lt;br /&gt;
&lt;br /&gt;
	fileClose(scriptHandler)&lt;br /&gt;
&lt;br /&gt;
	return scriptRaw&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function onScriptCompile(pCompiledLUA, pErrors, pScript)&lt;br /&gt;
	local compileSuccess = pErrors == 0&lt;br /&gt;
&lt;br /&gt;
	if not compileSuccess then&lt;br /&gt;
		outputDebugString(&amp;quot;[LUAC]: '&amp;quot;..pScript..&amp;quot;' failed to compile.&amp;quot;, 4, 255, 127, 0)&lt;br /&gt;
&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local compileError = apiCodes[pCompiledLUA]&lt;br /&gt;
&lt;br /&gt;
	if compileError then&lt;br /&gt;
		outputDebugString(&amp;quot;[LUAC]: '&amp;quot;..pScript..&amp;quot;' failed to compile - &amp;quot;..pCompiledLUA, 4, 255, 127, 0)&lt;br /&gt;
&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local compiledScript = fileCreate(&amp;quot;luac/&amp;quot;..pScript)&lt;br /&gt;
&lt;br /&gt;
	if not compiledScript then&lt;br /&gt;
		outputDebugString(&amp;quot;[LUAC]: '&amp;quot;..pScript..&amp;quot;' failed to create.&amp;quot;, 4, 255, 127, 0)&lt;br /&gt;
&lt;br /&gt;
		return false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	fileWrite(compiledScript, pCompiledLUA)&lt;br /&gt;
	fileClose(compiledScript)&lt;br /&gt;
&lt;br /&gt;
	outputDebugString(&amp;quot;[LUAC]: '&amp;quot;..pScript..&amp;quot;' compiled successfully.&amp;quot;, 4, 255, 127, 0)&lt;br /&gt;
&lt;br /&gt;
	return true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function compileLuaScripts(pPlayer)&lt;br /&gt;
	local fetchURL = string.format(&amp;quot;https://luac.mtasa.com/?compile=%i&amp;amp;debug=%i&amp;amp;obfuscate=%i&amp;quot;, compileEnabled, debugLevel, obfuscateLevel)&lt;br /&gt;
	local resourceScripts = loadScriptsFromMeta()&lt;br /&gt;
	local postData = true&lt;br /&gt;
&lt;br /&gt;
	for scriptID = 1, #resourceScripts do&lt;br /&gt;
		local scriptPath = resourceScripts[scriptID]&lt;br /&gt;
		local scriptRaw = loadResourceScript(scriptPath)&lt;br /&gt;
&lt;br /&gt;
		fetchRemote(fetchURL, onScriptCompile, scriptRaw, postData, scriptPath)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
addCommandHandler(&amp;quot;compilelua&amp;quot;, compileLuaScripts)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Changelog==&lt;br /&gt;
{{ChangelogHeader}}&lt;br /&gt;
{{ChangelogItem|2014-08-10|''encrypt'' has been renamed to ''obfuscate''.&amp;lt;br&amp;gt;''blockdecompile'' has been removed.}}&lt;/div&gt;</summary>
		<author><name>Sheenidgs137</name></author>
	</entry>
</feed>