Recently, while looking for a better Lua IDE I tried the Lua Development Tools by the Koneki project. The Koneki project focusses on machine-2-machine (M2M) development and hence does not yet support local run and debug configurations. With a support link to some helpful pages (which didn’t work straight away), I fiddled around a bit and got it working through the ‘external tools’ workaround, though still with some quirks. Also not sure it all works as it should, especially adding command line parameters is something I’ll be needing to fix still.
Here’s how to set it up (on Windows that is, but with some scripting also on other platforms);
- Download and install the standalone version (that’s what I used)
- Start it and create a simple new project called ‘test’; menu File > New > Lua project
- Create a new external tool config; menu Run > External Tools > External Tools Configurations…
- On the left pane right-click ‘Program’ and select New, then configure it as follows;
- Obviously, ‘Location’ should point to your local Lua VM
- Now add a statement to your test project; print(“Hello world”) and click the ‘External Tools’ button and select ‘lua_run’ as configured in step 4.
IMPORTANT: you must first select ‘main.lua’ in the script explorer or you’ll get an error;
- You should now see “Hello world” in the console window
Now that’s for running a Lua script directly, so how about debugging? The debug features go through a network connection to a remote device (or ‘localhost’), but it will require the script to be running with the Lua debugger modules loaded. So I created a batch file to do this.
- Download the debugger files (DBGP client) and store them in a folder ‘luadebug’ inside the directory where Eclipse is installed, for example; “C:\Program Files\EclipseLDT\debuglua”
- Download this batch file (downloaded 823 times) and store it in the same directory as the debugger files
- Create another ‘external tool’ config as detailed above, with the following settings;
- The path to the Lua VM is now in the ‘Arguments’ pane, so make sure it is correct for your local Lua VM.
- Add a debug configuration via menu; Run > Debug configurations…
- Configure it with the following settings;
- Start the debugger by selecting ‘lua_debugger’ from the debug button drop-down;
- Then start the application by selecting ‘lua_debug’ from the ‘External Tools’ button;
- The application will start with the debugger module loaded, it will connect to the debugger GUI within Eclipse.
In the debug configuration, a batch file is used. The batch file takes two parameters; a) path to the Lua VM, b) path to the debug target. The batch file will run the following steps;
- update the LUA_PATH environment variable such that the debugger modules will be in the search path
- start the Lua VM and initially execute the debugger modules
- then start the target Lua script
- after exiting it will restore the LUA_PATH variable
This approach prevents me from having to add the debugger code to the actual code. Though it is a windows batch file, it should be easy to port it to other platforms.
What’s to be improved still;
- start debugger and debug target with a single click
- allow for adding command line parameters to the target
- having some sort of default start file, instead of manually having to select the correct file before starting it
- the debugger requires a link to a specific project in its setup, so probably a specific setup is required per project (haven’t tested that yet)
- the batch file does not support setting the remote debugger IP, port or IDE key, so it always uses the defaults (127.0.0.1, 10000, luaidekey)
I’m interested in solutions to these, so if you find one let me know…