[EMAIL PROTECTED] said:
> Could someone please give me some little hints how to debug a lua
> script.
>
> (And sorry for the long mail - i wanted to give all infos)
>
> I have some experience with python, so when i don't get the result
> i expect, i use a "print" to see what's wrong.

I'm no lua expert, but here's what I use for lua debugging:

======= dbg.lua =======
dbg = {}
function dbg.echo(s)
        dbg.echon(s)
        dbg.echon('\n')
end

function dbg.echon(s)
        io.stderr:write(dbg.tostring(s))
end

function dbg.tostring(obj)
        local mt
        local tname
        local o
        if type(obj) == 'userdata' then
                mt = getmetatable(obj)
                o = '['
                if mt and mt.__index then
                        tname = mt.__index.__typename
                        if tname then
                                o = o .. tname
                        end
                end
                if obj.name then
                        if tname and tname == 'WClientWin' then
                                o = o .. ': ' .. dbg.tostring(obj:get_ident())
                        else
                                o = o .. ': ' .. obj:name()
                        end
                end
                return o .. ']'
        elseif type(obj) == 'table' then
                o = '{'
                sep = ''
                for k, v in pairs(obj)
                do
                        o = o .. sep .. dbg.tostring(k) .. '='
                        o = o .. dbg.tostring(v)
                        sep = ', '
                end
                return o .. '}'
        end
        return tostring(obj)
end
======= dbg.lua =======

add this to your ~/.ion3. Then, in the code you want to debug:

dopath("dbg")
dbg.echo('this has a newline')
dbg.echon('this prints without a newline')
-- you can also make a best-effort attempt to print arbitrary objects:
dbg.echo(table)

I haven't used any of this in a while, but it made things much easier
for me. I see the output in ~/.xsession-errors (debian unstable).

Jason

Reply via email to