dbg and stead fixes not ready

This commit is contained in:
p.kosyh 2010-06-16 05:05:23 +00:00
parent 85c65a9903
commit 96a52fd562
4 changed files with 39 additions and 11 deletions

View file

@ -15,6 +15,6 @@ function(f, s, cmd, x, y, ...)
end end
return nil,true return nil,true
end end
if f then return f(s, cmd, x, y, unpack(arg)) end return f(s, cmd, x, y, unpack(arg))
end) end)

View file

@ -3,10 +3,23 @@
-- for debug tools -- for debug tools
require "input" require "input"
function disp_obj()
local v = obj{
nam = 'disp',
dsc = function(s)
local r = s._txt
s._txt = nil;
return r
end
}
return v;
end
dump_obj = function(w) dump_obj = function(w)
w = ref(w) w = ref(w)
if type(w) ~= 'table' then if type(w) ~= 'table' then
return 'No such object.'; seen('disp')._txt = '^^No such object.';
return true
end end
local i,o local i,o
local rc='' local rc=''
@ -15,7 +28,8 @@ dump_obj = function(w)
rc = cat(rc, par(' ', 'Key:'..tostring(i), rc = cat(rc, par(' ', 'Key:'..tostring(i),
'Val:'..tostring(deref(o)))); 'Val:'..tostring(deref(o))));
end end
return rc; seen('disp')._txt = cat('^^', rc)
return true;
end end
list_objects = function() list_objects = function()
@ -30,6 +44,7 @@ list_objects = function()
'Nam:'..tostring(call(o, 'nam')), 'Nam:'..tostring(call(o, 'nam')),
'Disabled:'..tostring(isDisabled(o)))); 'Disabled:'..tostring(isDisabled(o))));
end end
seen('disp')._txt = rc
return rc return rc
end end
@ -45,6 +60,7 @@ list_inv = function()
'Taken:'..tostring(taken(o)))); 'Taken:'..tostring(taken(o))));
end end
if rc == '' then return end if rc == '' then return end
seen('disp')._txt = rc
return rc return rc
end end
@ -57,9 +73,11 @@ execute_cmd = room {
if type(s.obj[1]._txt) == 'string' then if type(s.obj[1]._txt) == 'string' then
local f = loadstring(s.obj[1]._txt); local f = loadstring(s.obj[1]._txt);
if f then if f then
return f(); seen('disp')._txt = cat('^^', f());
return true
end end
return "Error in exec."; seen('disp')._txt = "^^Error in exec.";
return true
end end
return back(); return back();
end, end,
@ -67,7 +85,9 @@ execute_cmd = room {
return back(); return back();
end, end,
obj = { inp('{Enter cmd}: ', 'return "Hello World!"'), obj = { inp('{Enter cmd}: ', 'return "Hello World!"'),
vobj(1, 'Back', '^{Back}')} vobj(1, 'Back', '^{Back}'),
new [[ disp_obj() ]],
}
} }
dump_object = room { dump_object = room {
@ -100,7 +120,8 @@ dump_object = room {
vobj(3, 'Player', '^{Dump player}'), vobj(3, 'Player', '^{Dump player}'),
vobj(4, 'Lifes', '^{Dump lifes}'), vobj(4, 'Lifes', '^{Dump lifes}'),
vobj(5, 'Ways', '^{Dump ways}'), vobj(5, 'Ways', '^{Dump ways}'),
vobj(1, 'Back', '^{Back}')} vobj(1, 'Back', '^{Back}'),
new[[ disp_obj() ]]}
} }
choose_location = dlg { choose_location = dlg {
@ -174,6 +195,7 @@ debug_dlg = dlg {
phr('Dump object...', true, [[pon(); return goto(dump_object);]]), phr('Dump object...', true, [[pon(); return goto(dump_object);]]),
phr('Exec Lua string...', true, [[pon(); return goto('execute_cmd')]]), phr('Exec Lua string...', true, [[pon(); return goto('execute_cmd')]]),
phr('Exit',true , [[pon(); return dbg_exit()]]), phr('Exit',true , [[pon(); return dbg_exit()]]),
new [[ disp_obj ]]
}, },
}; };
@ -194,13 +216,13 @@ function (f, s, cmd, ...)
if cmd == 'use_debug' then if cmd == 'use_debug' then
return debug_tool:inv() return debug_tool:inv()
end end
if f then return f(s, cmd, unpack(arg)) end return f(s, cmd, unpack(arg))
end) end)
input.key = hook(input.key, input.key = hook(input.key,
function(f, s, down, key, ...) function(f, s, down, key, ...)
if not here().debug and down and key == 'f7' then return 'use_debug' end if not here().debug and down and key == 'f7' then return 'use_debug' end
if f then return f(s, down, key, unpack(arg)) end return f(s, down, key, unpack(arg))
end) end)
putf('debug_tool', me()); putf('debug_tool', me());

View file

@ -201,7 +201,7 @@ game.action = hook(game.action, function (f, s, cmd, ...)
end end
return nil, true -- nothing todo return nil, true -- nothing todo
end end
if f then return f(s, cmd, unpack(arg)) end return f(s, cmd, unpack(arg))
end) end)
lookup_inp = function() lookup_inp = function()
@ -231,6 +231,7 @@ input_kbd = function(s, down, key)
input._txt = false input._txt = false
return "kbd_enter" return "kbd_enter"
end end
return
end end
if key == "backspace" then if key == "backspace" then
if input._txt == '' then if input._txt == '' then
@ -254,7 +255,7 @@ input.key = hook(input.key,
function(f, ...) function(f, ...)
local r = input_kbd(unpack(arg)) local r = input_kbd(unpack(arg))
if r then return r end if r then return r end
if f then return f(unpack(arg)) end return f(unpack(arg))
end) end)
function inp(info, txt) function inp(info, txt)

View file

@ -7,6 +7,8 @@ stead = {
os = os, os = os,
call_top = 0, call_top = 0,
cctx = { txt = nil, self = nil }, cctx = { txt = nil, self = nil },
nullfn = function()
end,
timer = function() timer = function()
if type(timer) == 'table' and type(timer.callback) == 'function' then if type(timer) == 'table' and type(timer.callback) == 'function' then
return timer:callback(); return timer:callback();
@ -2393,6 +2395,9 @@ end
function hook(o, f) function hook(o, f)
return function(...) return function(...)
if not o then
o = stead.nullfn
end
return f(o, unpack(arg)) return f(o, unpack(arg))
end end
end end