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.

Let’s go!

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.

http://www.eclipse.org/ldt/

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.

Vim

1

2

3

4

Debugger v1.3.0

Debugger: Trying to connect to 127.0.0.1:10000 ...

Debugger: Connection succeed.

Hello World!

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

Shell

1

2

$> 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

34 Comments on “Configuring Eclipse with Torch”

Thanks for the post Florian !
I did all steps, with one exception that i’m using lua 5.1 (this was automatically installed with torch).
I got the following error message when trying to run/debug with the new defined interpreter :
qlua: module ‘env’ not found

I tried to defined ‘th’ as interpreted instead of qlua, but then i get another message :
Could not load env, skipping

It’s a very informative for me. Thanks.
But I have a question.
At last part of your post, (New_configuration -> 1. Choose a name for script to execute Lua) Can I include various files rather than one file?

Hi,
This post is quite useful for me,thanks! But, I am wondering if I can use eclipse to create a project including lua and C files. To be specific, I mean how I can use eclipse to develop my own torch class or module. I find it is necessary for me to write codes at the C or CUDA level.

Thanks for the excellent tutorial.
I am using torch7 with Eclipse that was installed successfully using the instructions in this post. I am trying to display an Image. However while the image package is accessible, I am getting an error saying that qlua is running with -nographics andthus the image can not be displayed.
I wonder how to instruct/configure (qlua that is running) from eclipse to use graphics. I’ll be more than a happy to get some help on that.
Thanks in advance,
Amit

That is actually a bad news since the debugger crash with Mars/Neon. (Well, I tried Neon/Mars one month ago)
Yet, you can still use the Luna repository to have access to the old LDT environment.
I should send a bug report to the LDT team…

The default LDT installation points to a wrong version of LDT. I updated the tutorial to pick the good version.
Thus, one may can use Eclipse + Mars. I noticed a few bugs, but there is nothing critical

How can I use eclipse debugging with server? I succeed to use eclipse with your following description. However, I would like to use this eclipse with my server. Is there are way to connect this thing with server without installing eclipse in the server ??

Actually, autocompletion is not really a game dealer. (200 hundreds method on torch)
What really matters is debugging, refactoring tools and a enjoyable environment.
Otherwise, ITorch has autocompletion. I think that atom/zerobrane has an autocompletion too.

I was trying to use the “gnuplot” within Eclipse, but it kept giving me “Gnuplot terminal is not set” error in the console. When I run the same script in the Mac terminal, the plots pop up and everything worked fine.

Is this problem caused the Eclipse console, and is there a way to fix it?