How do you debug in DSB? I'd like a way to spit out a variable or string to 'log.txt', for example, rather than using the console - dsb_write(RGB, string).
Also I don't seem to be able to access the local obj (user data) with the below function. I'm investigating to see how I can override a trolin's AI, for example, outputting the wee beastie to file.
startup.lua
Code: Select all
dbg = {}
function dbg.echo(s)
dbg.echon(s)
dbg.echon('\n')
end
function dbg.echon(s)
-- io.stderr:write(dbg.tostring(s))
-- io.write(dbg.tostring(s))
--print(dbg.tostring(s))
dsb_write({100, 100, 100}, 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
-- Print an array
dbg.echo(xp_levelnames)
-- Print an array of arrays (not a table)
dbg.echo(player_colors)
-- Print a const
dbg.echo(NORTH)
-- Print text, capitals only.
dbg.echo('THIS IS A TEST')
-- My Favourite Trolin, serialised
--dbg.echo(tmp) --Doesn't really work, he defeats me (it's called at the end of dungeon.lua, not here, tmp=dsb_spawn("trolin", 1, 2, 8, CENTER)).
--test = dsb_find_arch(tmp)
--dbg.echo(test)
--dbg.echo(test["name"])