Thalassicus
Bytes and Nibblers
I've got us access to the Lua debug library in the latest patch. The main useful thing for modders is debug.traceback. Set this value in config.ini to use the debug library:
\Documents\My Games\Sid Meier's Civilization 5\config.ini
EnableLuaDebugLibrary = 1
Traceback helps track bugs. Look at the "Fatal" error level of the Lua logger in the unofficial patch (/ModTools/MT_LuaLogger.lua) for a practical example of how to use it. Say functions RootA and RootB call function SomeHelper. Error reports show one calls SomeHelper incorrectly, but it's not clear which. You can identify the culprit with a traceback:
NOTE: If the user does not have the debug library enabled, debug is nil and calling debug functions results in an error. Use "if debug then" before such calls. The debug library is not efficient and should be used sparingly.
The function debug.getlocal can access local variables of any active function in the stack. This can be useful to identify parameters of under-documented Event/LuaEvent functions in the API.
\Documents\My Games\Sid Meier's Civilization 5\config.ini
EnableLuaDebugLibrary = 1
Traceback helps track bugs. Look at the "Fatal" error level of the Lua logger in the unofficial patch (/ModTools/MT_LuaLogger.lua) for a practical example of how to use it. Say functions RootA and RootB call function SomeHelper. Error reports show one calls SomeHelper incorrectly, but it's not clear which. You can identify the culprit with a traceback:
PHP:
if debug then print(debug.traceback()) end
Code:
stack traceback:
[string "D:\Thalassicus\Documents\My Ga..."]:1111: in function '[B]SomeHelper[/B]'
[string "D:\Thalassicus\Documents\My Ga..."]:1119: in function '[B]RootB[/B]'
[string "D:\Thalassicus\Documents\My Ga..."]:115: in function ...
The main lua process (3) called RootB (2), which called SomeHelper (1), which had the print statement.
NOTE: If the user does not have the debug library enabled, debug is nil and calling debug functions results in an error. Use "if debug then" before such calls. The debug library is not efficient and should be used sparingly.
The function debug.getlocal can access local variables of any active function in the stack. This can be useful to identify parameters of under-documented Event/LuaEvent functions in the API.