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.
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.