|
|
|
|
Re: Proper method to debug Lua script from Luaj project [message #1219937 is a reply to message #1219915] |
Fri, 06 December 2013 22:35 |
Patrick Hoey Messages: 14 Registered: December 2013 |
Junior Member |
|
|
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 23:07] Report message to a moderator
|
|
|
|
|
Re: Proper method to debug Lua script from Luaj project [message #1220426 is a reply to message #1220377] |
Wed, 11 December 2013 17:01 |
Patrick Hoey Messages: 14 Registered: December 2013 |
Junior Member |
|
|
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 18:37] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.06191 seconds