Datasheet

This compiles each of the source files into a corresponding object file. Prior to linking these object files
into a dynamic link library, three object files are renamed to keep them from being included in the
library. These are the interpreter, the compiler, and a support file for the compiler. Finally, the interpreter
and compiler executables are created. The Lua interpreter is quite small, because its main functionality
comes from the dynamic link library. To test the Lua interpreter, execute the following command:
.\lua ..\test\hello.lua
This should result in the following output:
Hello world, from Lua 5.1!
Copy the import library and header files associated with the dynamic-link library to standard develop-
ment directories where your compiler and linker can find them. The approach taken here is to place
them in the
usr subdirectory beneath the SDK’s lib and include directories. These subdirectories can
then hold third-party files where they won’t be confused with toolkit files.
To install Lua, create a file with the following contents:
xcopy lua5.1.lib “%SDK_DIR%\lib\usr\*.*” /y
xcopy lua5.1-static.lib “%SDK_DIR%\lib\usr\*.*” /y
xcopy lua.exe “%UTIL_DIR%\*.*” /y
xcopy luac.exe “%UTIL_DIR%\*.*” /y
xcopy lua5.1.dll “%UTIL_DIR%\*.*” /y
xcopy lua.h “%SDK_DIR%\include\usr\*.*” /y
xcopy luaconf.h “%SDK_DIR%\include\usr\*.*” /y
xcopy lualib.h “%SDK_DIR%\include\usr\*.*” /y
xcopy lauxlib.h “%SDK_DIR%\include\usr\*.*” /y
Save this file as install.bat in the src directory. Copy the files by executing this batch script:
install
Building Lua with the Tiny C Compiler
The Tiny C Compiler (TCC) is a freely available C development system that you can use to build Lua on
both Linux and Windows. It is discussed here because it is an excellent way for Windows users who
don’t have a C toolkit to familiarize themselves with developing programs in C. The TCC web site
(
http://fabrice.bellard.free.fr/tcc) contains a link to the Window binary distribution in the
form of a zip file that includes everything you need to compile Lua.
TCC is perfectly suitable for building Lua itself, but you may want to consider a more full-featured SDK
if you intend to build extension libraries for Lua.
Download the zip file and place it in the directory above the point where you want to install TCC.
Assuming you are using the 7-zip utility and the version of the file is 0.9.23, extract the contents of the
file as follows:
7z x tcc-0.9.23.zip
14
Chapter 1: Getting Situated
04_069172 ch01.qxp 1/2/07 7:53 PM Page 14