lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Johnson,

> If I want to debug an embedded script, I assume that my scripts
> (client scripts) have to have access to the mobdebug module right? Is
> it OK if I copy mobdebug.lua file into my own project?

Yes and yes. You would need to make mobdebug.lua available to your
client scripts (you will also need a socket library). If "require" is
not available to you, you can just do "loadstring" on mobdebug.lua
content and because it internally does "package.loaded.mobdebug =
mobdebug", you can then simply do require('mobdebug').start() as you
would do in a normal situation. I've used this on some mobile
platforms that didn't support require or didn't have a file system.

> And is it possible to add a customizable interpreter target? I see
> that you have 3 targets now in ZBS/interpreters folder. Can I come up
> with one of my own program? Because I'd like to use the IDE to debug
> embedded scripts in my own program, and my program uses
> LuaJIT2-beta10. 

Yes, but it depends on how you want to start your (client)
application. You have two choices:
1. IDE starts the client application. In this case the application is
controlled by the ide and can only run on the same system; this is
what interpreters are for. You can definitely create your own, but you
can also set "path.lua = 'd:/lua/lua'" in cfg/user.lua (look at
cfg/user-sample.lua for details) to point to your luajit executable.

2. IDE "waits" for a debugging connection. You start your application
any way you want (locally or remotely) and as long as it can connect
over TCP, the IDE will be able to debug the application. You will
first need to Project | Start Debugger Server, which will start a
server on a particular port (it will tell you hostname:port it listens
on). You can then use this in your start() call:
require('mobdebug').start("hostname"[, port]).

In this case you run "luajit your-script.lua" and as long as you have
start() call in your-script.lua and have your-script.lua opened in the
IDE, you should be able to debug it. Please let me know if you run
into problems.

Not to make my answer too long, but there is another option that may
be of interest (and it's unique to this debugger/IDE). Instead of
adding start() call to your script, you can have a dummy script (let's
call it loop.lua) with just one line:

  require('mobdebug').loop("hostname")

When this script connects to the IDE, the ide will "push" whatever
script it has in the active window to the client. Depending on how
complex/long your deployment process is, this can be an easy
alternative to test quick code changes without any deployment at all
as you only need to deploy loop.lua once (plus all the other
resources/files that may be required by your app). I've used this
quite a bit for mobile development on various devices.

Paul.

On Thu, Sep 13, 2012 at 10:50 PM, Johnson Lin <arch.jslin@gmail.com> wrote:
> 2012/9/11 Paul K <paulclinger@yahoo.com>:
>> Hi Joshua,
>>
>>> Is there an example of hooking up the remote debugger into your own
>>> application?
>>
>> You can start the debugger using require('mobdebug').start() or
>> require('mobdebug').loop() commands. When  you use start(), the
>> debugger will start debugging of the current script. When you use
>> loop(), the controller can push any lua script to the client to debug;
>> this is useful for those cases when you want to run in an environment
>> (mobile, embedded, etc.) where you want to be able to easily change
>> the scripts to work with. In this case you can also reload the script
>> during debugging (this is how live coding functionality is implemented
>> in ZeroBraneStudio). I have some detailed notes and examples in the
>> README (https://github.com/pkulchenko/MobDebug/blob/master/examples/README).
>>
>>> Tilde uses a .vcproj file to describe a project folder hierarchy. That
>>> project folder hierarchy is used directly by the remote debugger to resolve
>>> the location of the file.  For instance, if the file on disk is
>>
>> MobDebug does something similar, but a bit simpler. It doesn't have
>> filename mapping, but it provides "baseline" command that can be used
>> to point to the project folder.
>>
>>> Tilde only supports debugging one master Lua state and all of its associated
>>> coroutines.  Does ZeroBrane Studio support debugging more than one master
>>> Lua state?
>>
>> I think it depends on what you mean by "more than one master state".
>> It the question is about whether it can debug coroutines, then yes.
>> There is require('mobdebug').coro() method you can call in your code
>> to enable debugging for coroutines. You can then set breakpoints and
>> step through yield/resume calls.
>>
>> If you mean debugging applications that use more than one lua state
>> (using multiple VM instances?), then you need to enable debugging for
>> each of those instances independently. You can then point them to two
>> different debug servers (using different port numbers in the start()
>> call); you probably won't be able to debug different VM states using
>> the same backend (at least not without changing the current backend).
>>
>> The debugger is Lua only, so it can do everything you can do with
>> debug hook in Lua. It has been tested on various versions of Windows,
>> OSX, and Linux, but it should probably work anywhere as long as you
>> have Lua 5.1. It can probably work with 5.2 using David's compat_env
>> module [1], but I haven't tested it yet.
>>
>> Paul.
>
> Hello Paul,
>
> I am the one who posted ZBS on G+ a few days ago and I didn't realize
> immediately that it was you who replied on my post. :)  I just posted
> a followup question, but I guess it'd be nice if others on the list
> can see my question as well, so I'll ask here too, also in case you
> didn't see my G+ reply. :)
>
> If I want to debug an embedded script, I assume that my scripts
> (client scripts) have to have access to the mobdebug module right? Is
> it OK if I copy mobdebug.lua file into my own project?
>
> And is it possible to add a customizable interpreter target? I see
> that you have 3 targets now in ZBS/interpreters folder. Can I come up
> with one of my own program? Because I'd like to use the IDE to debug
> embedded scripts in my own program, and my program uses
> LuaJIT2-beta10. 
>
> best,
> Johnson
>