This module enables Garrysmod to run precompiled lua bytecode in the lua interpreter. This has two advantages: one, lua doesn’t have to compile it so in theory it would start running faster, and two, people can’t read your code (as easily).

To use it, require the module, and use the global function runclua(“pathname”) to run a lua file. The file can be compiled or normal lua text, it doesn’t matter. The directory it starts in is the lua directory. You cannot load files from outside this directory, and you cannot load files with extensions other than .lua (if someone sees an exploitable error in the code, please tell me so I can fix it).

This module is perfectly safe to use. It is no different than someone running a file with include(), except that you might not know exactly what the code is going to do. It can’t do anything that a normal lua script can’t.

Download: Binary | Source

Q: So how do I get lua into bytecode?
A: You compile (or whatever the term is) it with a program called luac. You can download it here. Note: I didn’t write this, the creator of the lua language did. I didn’t modify the source code in any way except for the name of the output file, but if you’d rather compile it yourself, the msvc studio solution I used to compile this is here, and you can see where I got the source from on the lua website here.

Example use for the program would be (once you have a command prompt navigated to the directory where luac.exe is)

luac.exe -s inputfile.lua

This will compile inputfile.lua (from the same directory as luac.exe is in) and put the results into [del]luac.out[/del] compiled.lua (I modified the source to output that rather than luac.out, as it appeared more convenient). Rename this file to whatever you want, and you can load it with gm_clua. Run the program without arguments to see all the possible arguments you can use. The -s flag strips debug information.

Also note that you cannot use any of the Garrysmod specific lua additions (like ! for ~, /* */ and // comments, && for ‘and’ and || for ‘or’, etc) because this compiler was not written for garrysmod.

Thanks goes to haza, who wrote the code for the luaReader and that other struct I can’t remember the name of.

Fixed on 1/4/2011.

Could someone write a compiler for Glua?

Thanks for finding chrisaster :stuck_out_tongue:

Did you really need chrisaster to find it for you?


– DECOMPILER ERROR: Confused about usage of registers for local variables.
– Warning: undefined locals caused missing assignments!

It doesn’t matter even if it did work however, because if you try to datastream the contents of a file that has been compiled, all you get is the string “LuaQ”.

Very nice. I’ve been waiting for something like this. I wish the lua king rating was still here. I’ll just rate you useful. :smile:

If you run luac.exe with the switch “-s” (strip debug information) the decompiler won’t work anymore.


At least that worked a few years back when I was messing with compiled Lua.


Someone test and get back to me. If all works right the decompiler just crashes.

That’s the flag I compiled my lua with and it got the error I posted. It’s because it relies on the locals table in the debug information, and it fails if it’s not present or something.

Oh I see what you mean… it DOES prevent the decompiler? Sorry bad reading on my part I didn’t notice you included that switch.

Yeah, the use of locals (it said ‘undefined locals’, maybe to break it you have to declare a local without assigning a value) with the -s flag freaks decompilers out.

Fails to find the procedure “Lua_Load” in lua_shared.dll

Garry does not export the required functions since the last two mayor updates.

That’s disappointing D:
Oh also, you never linked me those files stone?

Could someone update the link to this? I’d love to use it but the download link 404’s.

I think this is it.

Oh my god, thank you, you have no idea how much this helps me! :smile:

Having trouble compiling my script, I made a quick script that just prints “hello” and that compiled fine so obviously I’m doing something wrong but… Not sure what -.-

Nevermind, got it.

It won’t work anymore. It requires lua_load which not many people can find. I don’t really plan on rewriting this for lua_load signatures, though.

lua_load for anyone who wants it.

// Function Signature Generated by Haza's SigGen.

function name = 

signature = "\x83\xEC\x14\x56\x57\x8B\x7C\x24\x2C\x85\xFF\x75\x05\xBF\xC0\xC1\x03\x10\x8B\x44\x24\x28\x8B\x4C\x24\x24\x8B\x74\x24\x20\x50\x51\x8D\x54\x24\x10\x52\x56\xE8\x45\x46\x01\x00\x57\x8D\x44\x24\x1C\x50\x56\xE8\xF9\x64\x00\x00\x83\xC4\x1C\x5F\x5E\x83\xC4\x14\xC3"

mask = "xxxxxxxxxxxx?xxxxxxxxxxxxxxxxxxxxxxxxxx????xxxxxxxx????xxxxxxxxx"

size(decimal) = "64"

Reupload please

Its broken anyways

Someone re-upload and haza posted lua_load so we can fix it anyway!