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.
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
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
You can start running/debugging your program!
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
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.
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
I add the link for other people:
https://wiki.eclipse.org/LDT/User_Area/User_Guide#Attach_Debug
Hi,
I was getting some weird characters when running scripts remotely and found out that it was because Eclipse console did not understand ANSI Escape characters.
If it also happens to you, just install
https://marketplace.eclipse.org/content/ansi-escape-console
PS: You will have to install marketplace first by adding Mars “repository” first.
Hope it helps
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
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
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 ?
https://groups.google.com/forum/#!topic/torch7/gG96UYCYhtg
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
I solved the problem. If someone get a error like me then you should install “luasocket” by “luarocks install luasocket”
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!
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.
The lua development tools (v 1.4: http://download.eclipse.org/ldt/releases/milestones/) is only supported on Eclipse-Mars right now. The other versions of Eclipse will return ‘Cannot perform Operation’ errors.
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…
I created a bug report : https://www.eclipse.org/forums/index.php/t/1073514/
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 ??
You have to follow those instructions:
https://wiki.eclipse.org/LDT/User_Area/User_Guides/User_Guide_1.0#Attach_Debug
Kind regards
“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.
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’:
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?
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
You might have downloaded the wrong lua Plugin with Mars. Try to uninstall/re-install the plugin from the ldt website:
https://eclipse.org/ldt/