steed/stead/dbg.lua

124 lines
3 KiB
Lua
Raw Normal View History

2010-06-14 14:41:55 +03:00
-- add this: reuire "dbg"
-- in your project
-- for debug tools
2010-06-14 15:55:29 +03:00
require "input"
2010-06-14 16:19:37 +03:00
list_objects = function()
local i,o
local rc = par(' ', 'Room:', tostring(deref(from())), 'Nam:',
call(from(),'nam'));
rc = cat(rc,'^');
for i,o in opairs(objs(from())) do
o = ref(o)
rc = cat(rc, par(' ', 'Id:', tostring(o.id), 'Obj:', tostring(deref(o)),
'Nam:', call(o, 'nam'), 'Disabled:',
tostring(isDisabled(o))),
'^');
end
return rc
end
2010-06-14 15:55:29 +03:00
execute_cmd = room {
nam = "Execute Lua code",
debug = true,
forcedsc = true,
dsc = "Enter Lua code here to exec.",
inp_enter = function(s)
if type(s.obj[1]._txt) == 'string' then
local f = loadstring(s.obj[1]._txt);
if f then
return f();
end
return "Error in exec.";
end
return back();
end,
2010-06-14 16:01:19 +03:00
act = function(s, w)
return back();
end,
obj = { inp('{Enter cmd}:', 'return "Hello World!"'),
vobj(1, 'Back', '^{Back}')}
2010-06-14 15:55:29 +03:00
}
2010-06-14 14:41:55 +03:00
choose_location = dlg {
debug = true,
2010-06-14 14:54:21 +03:00
forcedsc = true,
2010-06-14 14:41:55 +03:00
nam = 'Go to',
dsc = 'Select location.',
gen = function(s)
local k,v
objs(s):zap();
for k,v in pairs(_G) do
if isRoom(v) and not v.debug then
local n = call(v, 'nam');
2010-06-14 14:54:21 +03:00
put(phr(n, true, [[return goto("]]..k..[[")]]), s);
2010-06-14 14:41:55 +03:00
end
end
2010-06-14 15:55:29 +03:00
put (phr('Back',true, 'return back()'), s)
2010-06-14 14:41:55 +03:00
end
}
choose_object = dlg {
debug = true,
2010-06-14 14:54:21 +03:00
forcedsc = true,
2010-06-14 14:41:55 +03:00
nam = 'Get object',
dsc = 'Select object to get.',
gen = function(s)
local k,v
objs(s):zap();
for k,v in pairs(_G) do
if isObject(v) and not isRoom(v) and not isPlayer(v) and not v.debug and not have(v) and not isStatus(v) then
local n = call(v, 'nam');
2010-06-14 14:54:21 +03:00
put(phr(n, true, k..':enable(); return take("'..k..'")'), s);
2010-06-14 14:41:55 +03:00
end
end
2010-06-14 15:55:29 +03:00
put (phr('Back',true, 'return back()'), s)
2010-06-14 14:41:55 +03:00
end
}
drop_object = dlg {
debug = true,
2010-06-14 14:54:21 +03:00
forcedsc = true,
2010-06-14 14:41:55 +03:00
nam = 'Drop object',
dsc = 'Select object to drop.',
gen = function(s)
local k,v
objs(s):zap();
for k,v in pairs(_G) do
if isObject(v) and not isRoom(v) and not isPlayer(v) and not v.debug and have(v) then
local n = call(v, 'nam');
2010-06-14 14:54:21 +03:00
put (phr(k, true, 'drop("'..k..'","'..deref(from())..'")'), s)
2010-06-14 14:41:55 +03:00
end
end
2010-06-14 15:55:29 +03:00
put (phr('Back', true, 'return back()'), s)
2010-06-14 14:41:55 +03:00
end
}
debug_dlg = dlg {
2010-06-14 14:54:21 +03:00
debug = true,
forcedsc = true,
2010-06-14 14:41:55 +03:00
nam = 'Debug Tool',
dsc = 'Select tool.',
obj = {
2010-06-14 15:55:29 +03:00
phr('Go to location...', true, [[pon(); choose_location:gen(); return goto('choose_location')]]),
phr('Get object...', true, [[pon(); choose_object:gen(); return goto('choose_object')]]),
phr('Put object...', true, [[pon(); drop_object:gen(); return goto('drop_object')]]),
2010-06-14 16:19:37 +03:00
phr('Current scene...', true, [[pon(); return list_objects();]]),
2010-06-14 15:55:29 +03:00
phr('Exec Lua string...', true, [[pon(); drop_object:gen(); return goto('execute_cmd')]]),
phr('Exit',true , [[pon(); return goto(from())]]),
2010-06-14 14:41:55 +03:00
},
};
debug_tool = menu {
debug = true,
2010-06-14 14:54:21 +03:00
forcedsc = true,
2010-06-14 14:41:55 +03:00
nam = txtb('debug'),
inv = function(s)
debug_dlg.__from__ = deref(here());
me().where = 'debug_dlg'; -- force to go
local r = call(debug_dlg, 'enter');
return r;
end
};
putf('debug_tool', me());