Lua Executables and Debuggers

[ LiB ]

Lua Executables and Debuggers

Lua can be executed in chunks written in a file or in a string by using the following function's API commands, but normally a host program executes Lua. In UNIX systems, Lua scripts can be made into executable programs by using chmod and placing the #! /usr.local/bin/lua (or whatever the Lua path is) line at the top of a Lua file. Lua files can also be executed via the Windows command line the long way ( C:\lua-5.0\bin\Lua.exe file torun.lua ), but it won't run with a double mouse click until you've set up a path or a usable development environment for Lua. For now we'll just be using Lua with the interpreter, so do not fret about it.

Lua doesn't have any built-in debugging facilities. It does, however, offer an interface with special functions and hooks that allow a programmer to construct profilers and debugging tools. These hooks are called when the interpreter enters or leaves a function or changes code. Most of these functions are new as of Lua 5.0, which is good because the older call and hook functions had the a reputation of being slow and possibly volatile. Common debug functions are listed in Table 6.1.

Table 6.1. Lua Debug Functions




Returns current hook settings

debug.getinfo ()

Returns a table with information about a function

debug.getlocal ()

Returns name and value of the local variable

debug.getupvalue ()

Returns name and value of upvalue

debug.setlocal ()

Assigns a given value to a variable

sebug.setupvalue ()

Assigns a given value to an upvalue

debug.sethook ()

Sets the given function of a hook

debug.traceback ()

Returns a string with a traceback of the call stack

For more information on the built-in debugging facilties, check out the Lua user manual, which is available from the documentation page at:

One interesting development tool is the LuaIDE by Tristan Rybak, which is an integrated environment for developing Lua applications (see LuaIDE in action in Figure 6.1). The environment is currently in Beta testing but is available for free for commercial or non-commercial use. Despite being a prototype, LuaIDE supports output for building and debegging messages, step-into- and stop-over-type debugger commands, breakpoints, and a callstack trace window. You can find the latest version (including source code) at Tristan Rybak's Website, at luaide /.

Figure 6.1. The LuaIDE environment with a simple Lua source sample


[ LiB ]

Game Programming with Pyton, Lua and Ruby
Game Programming with Pyton, Lua and Ruby
Year: 2005
Pages: 133 © 2008-2017.
If you may any questions please contact us: