Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
02-25-2014, 04:39 PM
(This post was last modified: 02-25-2014, 04:40 PM by FakeTruth.)
(02-25-2014, 09:02 AM)paulclinger Wrote: (02-24-2014, 10:54 PM)FakeTruth Wrote: I tried to use remote debugging in my own project but it didn't work at all. I have compiled Lua into my project (static linked), could this be the problem and should I use the dll?
Yes, this can be problematic. What happens is this: you have an internal interpreter (statically linked), but socket library is linked against lua51.dll that is included with ZBS. So when you do require"socket" (directly or indirectly through require"mobdebug"), it loads socket.dll, which loads lua51.dll and you end up with two lua engines (and one of them may be "normal" lua and another LuaJIT), which leads to a crash.
There are two ways to deal with it:
(1) statically compile luasocket into your executable that has lua interpreter. That's what some engines do, like love2d.
(2) use a "proxy" DLL that replaces lua51.dll and will simply forward calls to your "static" executable. You can see some details here (http://studio.zerobrane.com/doc-lua52-debugging.html ) described in the context of Lua52 interpreter, but the same thing applies to statically compiled lua51 interpreter as well.
I can provide a proxy DLL if you want to experiment with it. In fact, I've been thinking about including it in the build/ folder of the IDE for cases like this. You'd just need to drop it into the same folder as your executable and the debugging should work.
That's what the documentation said as well. In my case nothing crashed however so I thought something else might be going wrong. Running ZBS and the debugger had no effect at all, it simply didn't do anything for me. (Also I'm using Lua 5.2).
Posts: 14
Threads: 0
Joined: Feb 2014
Thanks: 0
Given 0 thank(s) in 0 post(s)
(02-25-2014, 04:39 PM)FakeTruth Wrote: That's what the documentation said as well. In my case nothing crashed however so I thought something else might be going wrong. Running ZBS and the debugger had no effect at all, it simply didn't do anything for me. (Also I'm using Lua 5.2).
That's interesting. And you added "require('mobdebug').start()" to your script and there was no run-time error (so it found both socket module and mobdebug)?
Posts: 1,450
Threads: 53
Joined: Feb 2011
Thanks: 15
Given 120 thank(s) in 91 post(s)
02-27-2014, 04:40 AM
(This post was last modified: 02-27-2014, 05:46 AM by FakeTruth.)
Ah apparently it could not find mobdebug
Is there any way to set up the environment variables from within Visual Studio (2012)?
I tried to set it up like this http://i59.tinypic.com/2my13r4.png but it still cannot find the file.
This is what I get as an error
Code: Assets/Scripts/MyComponent.lua:2: module 'mobdebug' not found:
no field package.preload['mobdebug']
no file './mobdebug.lua'
no file '/lualibs/mobdebug/mobdebug.lua'
no file '/lualibs/mobdebug.lua'
no file '/bin/mobdebug.dll'
no file '/bin/clibs/mobdebug.dll'
I changed the Environments setting to
Code: ZBS=E:\Programs\ZeroBraneStudio
LUA_PATH=.\?.lua;E:\Programs\ZeroBraneStudio\lualibs\?\?.lua;E:\Programs\ZeroBraneStudio\lualibs\?.lua
LUA_CPATH=E:\Programs\ZeroBraneStudio\bin\?.dll;E:\Programs\ZeroBraneStudio\bin\clibs\?.dll
And now it crashes as expected
I tried to compile luasocket into my project but it seems incompatible with Lua 5.2. I made a few edits so it compiles but then it still crashes when require('mobdebug').start() is called.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
I have managed to get ZBS debugging working with MCS. There are a few hiccups along the way and it isn't yet too comfortable, but the basics are there
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
And we have a crash. Turns out two Lua DLLs don't like fighting each other We need to rename ours to match what LuaSocket expects to find, so that it's loaded instead of the ZBS's one.
Posts: 14
Threads: 0
Joined: Feb 2014
Thanks: 0
Given 0 thank(s) in 0 post(s)
02-28-2014, 08:55 AM
(This post was last modified: 02-28-2014, 08:56 AM by paulclinger.)
(02-27-2014, 04:40 AM)FakeTruth Wrote: I tried to compile luasocket into my project but it seems incompatible with Lua 5.2. I made a few edits so it compiles but then it still crashes when require('mobdebug').start() is called.
If you include the socket library, then none of the libraries that are shipped with ZBS should be used. What module does it crash in?
If you don't use statically compiled socket, then you need to reference clibs52/ instead of clibs/ folder as clibs/ has modules for Lua 5.1. You probably still need the proxy DLL (this one, but compiled for Lua52: http://lua-users.org/wiki/LuaProxyDllFour).
(02-28-2014, 06:27 AM)xoft Wrote: And we have a crash. Turns out two Lua DLLs don't like fighting each other We need to rename ours to match what LuaSocket expects to find, so that it's loaded instead of the ZBS's one.
It seems like you got it working based on the discussion here.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
Basic integration is finished, ZBS can be used to debug MCS plugins. Plus it provides a nice IDE with a good editor.
Now the question that burns me the most: Can the Analyze function be extended (natively or by a plugin) to analyze all the .lua files in a folder, loaded alphabetically one after another? So that we can quickly see if the plugin is using a global value rather than a local, or a typo.
Posts: 14
Threads: 0
Joined: Feb 2014
Thanks: 0
Given 0 thank(s) in 0 post(s)
(03-01-2014, 01:29 AM)xoft Wrote: Basic integration is finished, ZBS can be used to debug MCS plugins. Plus it provides a nice IDE with a good editor.
Now the question that burns me the most: Can the Analyze function be extended (natively or by a plugin) to analyze all the .lua files in a folder, loaded alphabetically one after another? So that we can quickly see if the plugin is using a global value rather than a local, or a typo.
Yes, it should be possible, but requires couple of tweaks to the analyzer to expose proper API. I can then make a plugin that will expose a menu item that will analyze all files (like Analyze All). Or maybe just integrate it into the IDE itself; something to think about... Thank you for the suggestion!
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
I think it would be more suited as a plugin, because the load order of the files is important, and a plugin could implement a specific load order. For example MCS loads all files alphabetically sorted, except for Info.lua, which is always loaded last. If there was a way to account for all this, I'd be super-happy
Posts: 14
Threads: 0
Joined: Feb 2014
Thanks: 0
Given 0 thank(s) in 0 post(s)
(03-01-2014, 11:53 AM)xoft Wrote: I think it would be more suited as a plugin, because the load order of the files is important, and a plugin could implement a specific load order. For example MCS loads all files alphabetically sorted, except for Info.lua, which is always loaded last. If there was a way to account for all this, I'd be super-happy
I got it working to process all the Lua files in a project directory one by one in the alphabetical order. Why would you care about a specific order? All the files are processed independently anyway. It would be the same result as if you opened each of them and run "Analyze", just in a more convenient way to process them all together in one click.
|