Configuring Eclipse with Torch
In a previous post ( coming 😉 ), I spoke about several IDE to use Torch. This post deals with configuring Eclipse with Torch.
I will start from scratch and I will assume that nothing but torch is installed on your computer. If you are familiar with programming, this post may be a bit boring
Furthermore, I am using Debian Jessie (stable) to have a standard environment.
STEP 1 : Installing Eclipse
Eclipse is an open and free Java IDE. It was first designed for Java developers but plug-ins can be installed to use other languages. It is one of the biggest (but heaviest) programming toolbox available. In our case, the plugin LDT (previously Koneki) enables to implement Lua programs. It has the following features:
- Basic Syntax coloring
- Basic auto-completion
- Basic refactoring tools
- Powerful Lua debugger and Interactive console
What make Eclipse better than most of the current Lua IDEs is its debugging abilities.
If Eclipse is not already installed, go to the LDT webpage and download it. Therefore, the LDT plug-in will already be installed.
If you want more advanced features, I would recommend to download the basic Eclipse (Java), it includes additional tools that are always welcomes. Once Eclipse is installed:
- go to Help –> Install New Software
- use the following address http://download.eclipse.org/ldt/releases/stable . Loading the page may be a bit slow.
- Go to Programming Languages and select the following tools:
- Lua Developments Tools (required)
- Lua Development Tools – Remote Development Support (optional)
- Lua Development Tools – Remote Development Support SDK (optional)
- Lua Development Tools SDK (optional)
I discourage people to use the classic repository (apt-get, yum) to install Eclipse. Eclipse packages are often a bit out-dated for stability reasons.
Once the plug-in is installed you should have the Lua perspective available (Click on the upper-right button to select the Lua Perspective). An Eclipse’s perspective is a working environment for given a task. If you want to code Java, you need to use Java Perspective, if you are dealing with advanced Git Features, you need to use the Git perspective and so on.
WARNING : I upgraded to Eclipse Mars, the LDT plug-in seems to not properly work. The debugger would disconnect for some unknown reasons. I had to rollback to Luna to work.
STEP 2 : Creating a Lua Project
From this point, it is assumed that Lua perspective is activated
By default, Eclipse is using Lua 5.1. Deep learning is hype, so let use the latest version of Lua, aka, 5.2!
- Go to Windows –> Select Preference
- Go to Execution Environment and select lua-5.2
- Go to Grammars and select lua 5.2
- Go to Interpreters and select lua 5.2
This will enable to have a Lua with a 5.2 environment. A few change will be made while using Torch, but let keep on.
It is time to create out first project :
- Go to File–>New–>Lua Project
- Type your project name
- The workspace is the folder where eclipse will save/execute your program. Keep it by default for your first programs
- The target environment/grammar should be lua-5.2. Otherwise change it by using Configure environment
- Working set are used when programming with several projects at once. There are not needed for now but keep this feature in mind for later purposes
- Click to Next
- This windows allows you to pick your source folder, select some external dependencies and so on. Most of the time, the default configuration is enough!4
- Click on Finish!
As some may have notice, there is nothing related to Torch, but, it will come shortly!
So let type our first Lua non-torch program!
As you can see, there is syntax coloring, auto-completion, static code analysis and so-on in a fashion way!
If you directly run the program by clicking on the Run/Debug button in the menu, it should work.
Debugger: Trying to connect to 127.0.0.1:10000 ...
Debugger: Connection succeed.
STEP 3 : Linking Torch to Eclipse!
This is the hot topic! A lot of Lua interpreters are already embedded in LDT, but torch is not. So we are going to manually configure the interpretor. One should know that Torch does not follow the standard LuaDocs format. Therefore, the auto-completion will not work. I think it can be tricked, but that’s another topic.
First, we need to install some external dependency
$> luarocks install luasocket
$> sudo apt-get install libcanberra-gtk-module
Go back to eclipse to configure the interpreter:
- Go to Windows–>Project–>Preference
- Go to Lua Interpreters –> Add…
- Interpreter type : Lua 5.2 *
- Interpreter executable : path_to_qlua *
- by default, qlua is installed on ~/torch/install/bin/qlua (
- You may type “$> which th” in a terminal to get the interpreter installation path
- Interpreter arguments : -lenv
- Linked Execution Environment : Lua-5.2
- Click on Ok
- Pick Torch as your default interpreter
* If you are not using the qt framework in your project, you may use luaJit instead. LuaJit should be a lot faster!
We now have to configure the “run configurations” to execute our program in both debug/release mode. First the debug and most important, debug mode.
- Go to the upper-left
- Select the arrow next to the weird beetle
- Look for Lua Application –> Right Click
- Select new
A “New_configuration” project should open, select it.
- Choose a name for script to execute Lua
- Check that your default Interpreter is Torch
- Break on first Line –> that will force to use the debug perspective on execution
You can start running/debugging your program!