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:

  1. go to¬†Help –> Install New Software
  2. use the following address  http://download.eclipse.org/ldt/releases/stable . Loading the page may be a bit slow.
  3. 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)

eclipse-install-ldt

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.

selecting perspective

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!

  1. Go to Windows –> Select PreferenceSelectProjectPref
  2. Go to Execution Environment and select lua-5.2
  3. Go to Grammars and select lua 5.2
  4. Go to Interpreters and select lua 5.2

UpdateEnvironment

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 :

  1. Go to File–>New–>Lua ProjectNewLua Project
  2. Type your project name
  3. The workspace is the folder where eclipse will save/execute your program. Keep it by default for your first programs
  4. The target environment/grammar should be lua-5.2. Otherwise change it by using Configure environment
  5. 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
  6. Click to Next
    NewProject2
  7. 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
  8. Click on Finish!

NewProject3

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!

First 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.

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

Go back to eclipse to configure the interpreter:

  1. Go to Windows–>Project–>Preference
  2. 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
  1. Click on Ok
  2. 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!

NewInterpreters

PickTorchInterpreter

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.

  1. Go to the upper-left
  2. Select the arrow next to the weird beetle
  3. Look for Lua Application –> Right Click
  4. Select new

CreateNewConf1

A “New_configuration” project should open, select it.

  1. Choose a name for script to execute Lua
  2. Check that your default Interpreter is Torch
  3. Break on first Line –> that will force to use the debug perspective on execution

DebugConfiguration

You can start running/debugging your program!

34 Comments on “Configuring Eclipse with Torch

  1. 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

    However, the packagse ‘env’ is properly installed.

    • Can you try the following step:

      Start torch (~/torch/install/bin/torch)
      type : help(torch.rand) -> Does it work?
      type : require(“env”) -> does it work?
      If both works, you may remove the -lenv arguments from eclipse.

      Then, try to execute a basic program in debug mode, set a break point and try the previous instructions in eclipse’s interactive console.

      The torch package is modified on a regular basis and the -lenv flag seems to no longer be required

  2. The figures on the tutorial is not seen. Before I bookmarked your site, but it changed. Could you please link the figures?

    Regards

    • Thank for reporting. It is now fixed.
      I moved the website from one server to another and the database was not correctly updated.

  3. Hi,

    I am trying to remotely debug torch script. Is there a way I start a DBGP server on my remote computer and connect from my local one?

    Thanks

  4. I’ve setup the debugger and I get the error:

    qlua: [string “io.stdout:setvbuf(‚Äėno‚Äô)”]:1: bad argument #1 to ‘setvbuf’ (string expected, got nil)
    stack traceback:
    [C]: at 0x7fdf21fc2970
    [C]: in function ‘setvbuf’
    [string “io.stdout:setvbuf(‚Äėno‚Äô)”]:1: in main chunk

    The debugger session terminates. Any idea what’s going on?

    • The fix was: I removed the -e “stuff” option and it work fine.

      • ThankŇõ for reporting. Torch is evolving, thus some options are no more required. I am going to edit the post

  5. 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?

    I want to include many .lua files in my project.

    Again Thanks~

    • Hi Eunsoo,
      What do you mean by including many .lua files?
      “Choose a name for script to execute Lua” is the entry point of your, script. In other words, it is your int main() function.

      If you need several entry points, you can create several configuration to run. Then, you pick the one you want while starting the script.

      If you need to execute several script in a raw, you can create a single file and call dofile(“script1.lua”), dofile(“script2.lua”) etc.

      Tell me if I misunderstood your issue :)

      Kind regards,
      STRUB Florian

  6. Thanks for very informative setup for Torch7 In eclipse. I’m wondering is there any way to enable auto-completion in eclipse with Torch 7 ?

  7. I can’t run the debugger I got following errors. I did exactly on the post and I was succeed to run it but not debugging. Can you help?

    stack traceback:
    [C]: at 0x010fa24b90
    [C]: in function ‘require’
    …/org.eclipse.osgi/455/0/.cp/script/external/debugger.lua:176: in function
    [C]: in function ‘require’
    …/org.eclipse.osgi/455/0/.cp/script/external/debugger.lua:3239: in function
    [string “require (‘debugger’)();”]:1: in main chunk

    • qlua: …/org.eclipse.osgi/455/0/.cp/script/external/debugger.lua:176: module ‘socket’ not found:
      no field package.preload[‘socket’]
      no file ‘./socket.lua’
      no file ‘/Users/sangpil_kim/torch/install/share/luajit-2.1.0-alpha/socket.lua’
      […]
      no file ‘/usr/local/lib/lua/5.1/loadall.so’
      stack traceback:
      [C]: at 0x010d702b90
      [C]: in function ‘require’
      …/org.eclipse.osgi/455/0/.cp/script/external/debugger.lua:176: in function
      [C]: in function ‘require’
      …/org.eclipse.osgi/455/0/.cp/script/external/debugger.lua:3239: in function
      [string “require (‘debugger’)();”]:1: in main chunk

  8. I solved the problem. If someone get a error like me then you should install “luasocket” by “luarocks install luasocket”

  9. 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.

    Kind regards

    • Hi,
      I have not tried to use C++ and Lua at once.
      Yet, if I have to give a shot, I would do it in the following way:

      – Step 1 : create a C++ project by using torch source (Add the debug flag -g for debugging symbol + set the optimzation flag to -O0 )
      – Step 2 : compile the code by calling the ./install.sh script from eclipse
      – Step 3 : Put a breakpoint in your function
      – Step 3 : create a Lua project
      – Step 4 : start the Lua Project in debug mode
      – Step 5 : Attach the processId of the interpreter with eclipse. (Eclipse is able to debug two process at once).
      – Step 6 : Call your lua command in your code by using some signal. (For instance, you may use the standard input to let you attach the C++ process)

      To industrialize the step 5&6, I would attach the processId of the interpreter by modifying the Lua Running command:
      https://wiki.eclipse.org/CDT/StandaloneDebugger + ( ps / awk)

      Then, I would untangle the c++ compilation to avoid compiling the full project. Yet, this step scares me a bit!

  10. 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

    • Hi,
      Can you send me your backtrace please.
      In the worst case, you can still save your image and display it thanks to iTorch or gfx.

    • 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…

  11. 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 ??

  12. “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.”

    I wish I had read that before I downloaded and installed eclipse. I might as well use a barebones editor then.

    • 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.

  13. Hello, I have installed LUA as you mentioned but while running a toch program i am getting an error: error loading module ‘libpaths’ from file ‘/home/shubham/torch/install/lib/lua/5.2/libpaths.so’:

  14. Thanks for the posting~

    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?

  15. I have given the interpreter as Luajit and tried to configure Torch with eclipse but when i try to call the debug configuration i get the following error with a pop window

    • An error has occurred. See error log for more details.
      org.eclipse.ldt.debug.ui.internal.launchconfiguration.local.LuaMainLaunchConfigurationTab.setWarningMessage(Ljava/lang/String;)V

Leave a Reply

Your email address will not be published.