Some notes on the C code of the Lua Compiler
Lua 5.3.1
Compiling using Code::Blocks
- Download the Lua source code
- Create a console application with default settings on code blocks
- copy all the files from the src directory of the lua source to the code::blocks project directory
- Add all source files except luac.c to the project
- Build!
Compiling using MinGW
- Install MinGW from MSYS2 as described here
- Start the MinGW command line:
-
> C:\msys64\mingw64.exe
for 64 bit -
> C:\msys64\mingw32.exe
for 32 bit
-
- Go to tua source code downloaded directory
- Execute:
-
> mingw32-make mingw
-
In Linux
- To compile the dynamic library add the following to the Makefile in the src directory:
with the static one:
Code details
- lua.c is the main file
- The main prompt that provides the command line is inside function pmain in lua.c specifically the function dotty(L)
- There is a file loadlib.c which contains all the code to implement the require function. That file basically implements dynamic library linking code for different operating systems
- To change the default package.path and package.cpath edit it in the luaconf.h file. A sample for adding support for LuaDist directory structure:
- For my paths I have it like this for Lua5.2:
- Another way to change the default path is to create a separate include file like myconf.h and in that undef the LUA_PATH_DEFAULT and LUA_CPATH_DEFAULT variables and then define your own. To compile Lua with this include file do something like:
- Note the quotes around myconf.h
- For compatibility with IUP (IUP 3.15 also) do
- Adding a submodule custom searcher in the pmain function of lua.c helps find sub modules in lua properly. The code added is:
- It is added in the pmain function after handle_luainit is done. This adds a searcher in package.searchers. So if a path is a/b/?/c/?.lua then require("x.y") would search in the path a/b/x/c/x/y.lua path rather than the normal a/b/x/y/c/x/y.lua