Compile Lua Code and store the bytecode in a new file

1.3k Views Asked by At

I know it is possible to compile the Lua code using LuaC as described here:

luac is the Lua compiler. It translates programs written in the Lua programming language into binary files that can be loaded and executed with lua_dofile in C or with dofile in Lua.

The problem is: I need to create an application in .Net (more specifically in C#) that will receive an input of multiple 'regular' *.lua files and then compile all of them to new files.

2

There are 2 best solutions below

0
On

I ended up having to call LuaC.exe from inside my application.

My solution was doing the following:

string outFile = Path.GetDirectoryName(path) + "\\" + Path.GetFileNameWithoutExtension(path) + ".out";
System.Diagnostics.Process.Start(System.IO.Directory.GetCurrentDirectory() + "\\luac.exe", "-o \"" + outFile + "\" \"" + path + "\"");

path = outFile;
0
On

loadfile followed by string.dump does essentially what luac does.