Proper method to debug Lua script from Luaj project [message #1219439] |
Tue, 03 December 2013 16:12  |
Eclipse User |
|
|
|
I have been following the http://wiki.eclipse.org/Koneki/LDT/Developer_Area/User_Guides/User_Guide_1.0#Launching_DBGp_Client
as well as googling around for possible solutions.
Here is my problem. I am trying to debug a Lua script from Eclipse with the Koneki project plugin, and I have set a breakpoint within a Lua function. The breakpoint never gets hit, and it appears that the Lua attach debug process terminates. I even set the debug option to "Break at the first line" and this does work, but then as soon as I continue, the debug process terminates.
In my mind, I would think that I would start the DBGp Server (Lua Attach to Application), and then start my java app (which loads and calls functions of the Lua scripts via LuaJ). I then run the "Lua Application" with my lua script in order for the lua client to load.
I guess I am not clear on how to properly debug a Lua script within Eclipse (using Koneki Lua plugin) when the scripts are loaded from LuaJ within a Java application.
|
|
|
|
|
|
Re: Proper method to debug Lua script from Luaj project [message #1219937 is a reply to message #1219915] |
Fri, 06 December 2013 17:35   |
Eclipse User |
|
|
|
Ok, now I understand where my confusion was. I am new to the Lua environment, and it was made more confusing by using a third party integration tool (LuaJ) to interact with the Lua scripts. I now understand that there are two distinct methods to debug in Eclipse (LDT) with Lua. What I did not understand before is that LuaJ library itself is the interpreter, just like if Lua was installed with an executable.
Once I connected the dots, I understood how to make my debug target. For this example, I am using the "Lua Application" target for debugging.
The first step was adding my own interpreter. Under "Lua Application", I "managed interpreters" (generic Lua) in order to add LuaJ. It appears that the "Interpreter executable" field expects a specific file, so passing in the LuaJ command was not an option. I created a batch file (on Windows) and wrapped the LuaJ command in the file with the following line:
java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua %*
This allows for all the parameters to be passed to the batch file as if it was an executable.
In the environment of the "Lua Application" debug target, I set both LUA_PATH and LUA_CPATH (append environment):
LUA_PATH = F:/Users/phoey/phoey_phoeyPC/workspace/cyberpunkgame-android/assets/data/scripts/?.lua;?.lua;D:/luarocks/lib/lua/5.1/?.lua;d:/luarocks/2.1/lua/?/init.lua
LUA_CPATH = D:/luarocks/lib/lua/5.1/?.dll
I also made sure my "Working Directory" was set to where my lua scripts were (through the Arguments tab)
My first problem was the following:
F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts>java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua -e "require ('debugger')();" F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts\atm.lua
org.luaj.vm2.LuaError: @debugger.lua:2283 Luaj-jse 3.0-beta1is not supported.
stack traceback:
debugger.lua:2265: in main chunk
string:1: in main chunk
[Java]: in ?
at org.luaj.vm2.lib.BaseLib$error.call(Unknown Source)
at org.luaj.vm2.lib.TwoArgFunction.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.onInvoke(Unknown Source)
at org.luaj.vm2.LuaClosure.invoke(Unknown Source)
at lua.processScript(Unknown Source)
at lua.main(Unknown Source)
The LuaJ interpreter returns "Luaj-jse 3.0-beta1" (supports Lua 5.2) but the client debugger.lua script expects either a "Lua 5.1" or "Lua 5.2". I modified the script for LuaJ support by setting the version to "Lua 5.2".
But now, after resolving that issue, I keep getting the following error:
F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts>java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua -e "require ('debugger')();" F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts\atm.lua
org.luaj.vm2.LuaError: @debugger.lua:1704 Unable to determine the working directory.
stack traceback:
debugger.lua:1702: in function 'init'
debugger.lua:2685: in function <debugger.lua:2676>
string:1: in main chunk
[Java]: in ?
at org.luaj.vm2.lib.BaseLib$error.call(Unknown Source)
at org.luaj.vm2.lib.TwoArgFunction.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.onInvoke(Unknown Source)
at org.luaj.vm2.LuaClosure.invoke(Unknown Source)
at lua.processScript(Unknown Source)
at lua.main(Unknown Source)
The environment variables are set as well as the working directory. In putting print statements in, I have found that the M.init() is being called (in debugger.lua) where both executionplatform and workingdirectory parameters are nil.
The function tries to guess if the OS is windows with the following call:
local p = io.popen("echo %os%")
but the value returned is nil, and so the OS is set to Unix as the default and therefore never enters the windows path parsing code.
Any ideas on how to troubleshoot this issue? I don't understand why the io call (to open the process and run the echo command) is failing.
UPDATE: I added an assert around the io.popen call to get additional information. This is what I get:
@debugger.lua:1642 io error: Cannot run program "echo": CreateProcess error=2, The system cannot find the file specified
stack traceback:
debugger.lua:1641: in function <debugger.lua:1640>
[Java]: in function 'pcall'
debugger.lua:1651: in function 'init'
debugger.lua:2692: in function <debugger.lua:2683>
string:1: in main chunk
[Java]: in ?
UPDATE 2
I changed the line in iswindows() from
local p = io.popen("echo %os%")
to
local p = io.popen("cmd /C echo %os%")
and now it recognizes my system as Windows_NT (I am developing on a Windows 7 64bit system)
I also changed the line in getworkingdirectory() from
local p = io.popen("echo %cd%")
to
local p = io.popen("cmd /C echo %cd%")
Now the script can determine my working directory correctly.
Unfortunately, I am now getting this error:
F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts>java.exe -cp F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame\libs\luaj-jse-3.0-beta1.jar lua -e "require ('debugger')();" F:\Users\phoey\phoey_phoeyPC\workspace\cyberpunkgame-android\assets\data\scripts\atm.lua
org.luaj.vm2.LuaError: @debugger.lua:173 module 'socket' not found: socket
no field package.preload['socket']
socket.lua
no class 'socket'
stack traceback:
debugger.lua:172: in function 'require'
debugger.lua:2696: in function <debugger.lua:2683>
string:1: in main chunk
[Java]: in ?
at org.luaj.vm2.LuaValue.error(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.lib.PackageLib$require.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.call(Unknown Source)
at org.luaj.vm2.LuaClosure.execute(Unknown Source)
at org.luaj.vm2.LuaClosure.onInvoke(Unknown Source)
at org.luaj.vm2.LuaClosure.invoke(Unknown Source)
at lua.processScript(Unknown Source)
at lua.main(Unknown Source)
As stated earlier, I have the socket.lua (core.dll) in my LUA_PATH and LUA_CPATH respectively, so I am not sure why it is ignoring the paths. Any ideas?
[Updated on: Fri, 06 December 2013 18:07] by Moderator
|
|
|
|
|
Re: Proper method to debug Lua script from Luaj project [message #1220426 is a reply to message #1220377] |
Wed, 11 December 2013 12:01  |
Eclipse User |
|
|
|
Hello Simon,
Thanks for your reply.
In the last few days, I ported my Java source from using LuaJ to JNLua, including the Lua scripts. This actually gave me more control over the Lua calls made in Java, and so I am closer to the Lua layer. Now the LUA_PATH and LUA_CPATH environment variables are respected, and I can easily load third party native libraries in Lua using the JNLua interface.
I posted a follow up with another question regarding attaching to a Java process after I set all of this up. The post is here:
http://www.eclipse.org/forums/index.php/m/1220255/
In summary, there appear to be problems with debugging with LDT where the files are loaded from lua_load() (the dynamic code comment). There was one little excerpt in this forum that caught my attention in how the developer solved his problem:
"To use an embedded script you need to load it in the style of luaL_loadfile, pushing the filename onto the stack first with lua_pushfstring(L, "@%s", filename); and removing it after calling luaL_loadbuffer."
Posting is here: http://www.eclipse.org/forums/index.php/mv/msg/486668/1057860/#msg_1057860
I posted a request with JNLua project to see if it makes sense to expose lua_pushfstring() and luaL_loadbuffer() but have not yet received a reply.
Either way, I found an alternative with ZeroBrane's Studio Lua Debugger. I installed and set a breakpoint, and without much configuration was able to debug my script.
Thanks again.
[Updated on: Wed, 11 December 2013 13:37] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05776 seconds