DEBUGGING
Debugging code comes with the territory when programming and XLua code is not the easiest to debug because XLua does not have a wide range of specialized debugging tools; however, it has enough to get by. There are FOUR elements you should have in place do before debugging.
FIRST: Get the latest version of XLua, 1.3+. This version has some features that make debugging a bit easier. There are some caveats:
- IF you are going to experiment with XLua coding by modifying the scripts in default X-Plane aircraft, then be aware that many of those aircraft use older versions of XLua and some methods described here will not work unless you replace those older versions of XLua with the newest versions.
- The best way to avoid messing up default aircraft is to simply copy the scripts folder out of the Xlua folder to a backup location before you start experimenting. If you break something, you can always copy that folder back into the XLua folder and try again.
- If you DO replace the XLua binary plugins (*.xpl) in the default aircraft with the latest version, then when updating X-Plane, the installer will want to re-install the old versions, but will give you the option to keep them. Running the installer and selecting "Overwrite" options will always restore aircraft to their default state.
SECOND: Assign the default X-Plane command, laminar/xlua/reload_all_scripts to a convenient key-combo like SHIFT-spacebar. It will get a lot of use and speed debugging up significantly as the aircraft does not have to be reloaded in most cases. This command is only available in XLua version 1.3+
THIRD Get a good text editor that, at the very minimum, can display line numbers. Beyond that, the following features are helpful as projects grow in size.
- Syntax color highlighting
- project files browser
- ability to search/replace across multiple files
- ability to search using GREP patterns
- Symbol browser/summary
Text editors/IDEs are very personal choices and users are quite passionate about the tools they prefer to use. You will have to do your own research and experimentation to decide for yourself which one you prefer to use. That being said, the following TWO editors are free, cross-platform and have all the desirable features and easily capable of handling the largest XLua projects. Beyond these recommendations, you will have to do your own research.
FOURTH Get Dataref Editor (DRE) or Dataref Tool (DRT) by Lee Baker.
There are essentially 2 debugging activities when coding in XLua.
Determining if your scripts are "crashing" and if so, what line of code in what file is causing the crash. Determining the value of a Lua variable at runtime.
• FIRST: You will need to launch X-Plane from a command line application in order to print out any debug information.
• THIRD: Assign the default X-Plane command,
laminar/xlua/reload_all_scriptsto a convenient key-combo like SHIFT-spacebar. (Requires XLua 1.3+)
When you launch X-Plane from the command line, then that command line window will remain open while X-Plane is running. In Lua, when you use the print() function, then that output will go to the terminal. In this way, you can print Lua values and see their values in the terminal window.
FLOOD the terminal with output.
On Mac OS
OnWindows
- Show users how to make a shortcut?