From 96a52fd562c5fd2d2634606d412afd5729bcaffa Mon Sep 17 00:00:00 2001
From: "p.kosyh"
Date: Wed, 16 Jun 2010 05:05:23 +0000
Subject: [PATCH] dbg and stead fixes not ready
---
stead/click.lua | 2 +-
stead/dbg.lua | 38 ++++++++++++++++++++++++++++++--------
stead/input.lua | 5 +++--
stead/stead.lua | 5 +++++
4 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/stead/click.lua b/stead/click.lua
index be0b4d0..26873f2 100644
--- a/stead/click.lua
+++ b/stead/click.lua
@@ -15,6 +15,6 @@ function(f, s, cmd, x, y, ...)
end
return nil,true
end
- if f then return f(s, cmd, x, y, unpack(arg)) end
+ return f(s, cmd, x, y, unpack(arg))
end)
diff --git a/stead/dbg.lua b/stead/dbg.lua
index d23294b..0185b01 100644
--- a/stead/dbg.lua
+++ b/stead/dbg.lua
@@ -3,10 +3,23 @@
-- for debug tools
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)
w = ref(w)
if type(w) ~= 'table' then
- return 'No such object.';
+ seen('disp')._txt = '^^No such object.';
+ return true
end
local i,o
local rc=''
@@ -15,7 +28,8 @@ dump_obj = function(w)
rc = cat(rc, par(' ', 'Key:'..tostring(i),
'Val:'..tostring(deref(o))));
end
- return rc;
+ seen('disp')._txt = cat('^^', rc)
+ return true;
end
list_objects = function()
@@ -30,6 +44,7 @@ list_objects = function()
'Nam:'..tostring(call(o, 'nam')),
'Disabled:'..tostring(isDisabled(o))));
end
+ seen('disp')._txt = rc
return rc
end
@@ -45,6 +60,7 @@ list_inv = function()
'Taken:'..tostring(taken(o))));
end
if rc == '' then return end
+ seen('disp')._txt = rc
return rc
end
@@ -57,9 +73,11 @@ execute_cmd = room {
if type(s.obj[1]._txt) == 'string' then
local f = loadstring(s.obj[1]._txt);
if f then
- return f();
+ seen('disp')._txt = cat('^^', f());
+ return true
end
- return "Error in exec.";
+ seen('disp')._txt = "^^Error in exec.";
+ return true
end
return back();
end,
@@ -67,7 +85,9 @@ execute_cmd = room {
return back();
end,
obj = { inp('{Enter cmd}: ', 'return "Hello World!"'),
- vobj(1, 'Back', '^{Back}')}
+ vobj(1, 'Back', '^{Back}'),
+ new [[ disp_obj() ]],
+ }
}
dump_object = room {
@@ -100,7 +120,8 @@ dump_object = room {
vobj(3, 'Player', '^{Dump player}'),
vobj(4, 'Lifes', '^{Dump lifes}'),
vobj(5, 'Ways', '^{Dump ways}'),
- vobj(1, 'Back', '^{Back}')}
+ vobj(1, 'Back', '^{Back}'),
+ new[[ disp_obj() ]]}
}
choose_location = dlg {
@@ -174,6 +195,7 @@ debug_dlg = dlg {
phr('Dump object...', true, [[pon(); return goto(dump_object);]]),
phr('Exec Lua string...', true, [[pon(); return goto('execute_cmd')]]),
phr('Exit',true , [[pon(); return dbg_exit()]]),
+ new [[ disp_obj ]]
},
};
@@ -194,13 +216,13 @@ function (f, s, cmd, ...)
if cmd == 'use_debug' then
return debug_tool:inv()
end
- if f then return f(s, cmd, unpack(arg)) end
+ return f(s, cmd, unpack(arg))
end)
input.key = hook(input.key,
function(f, s, down, key, ...)
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)
putf('debug_tool', me());
diff --git a/stead/input.lua b/stead/input.lua
index 0f77cd2..af3e110 100644
--- a/stead/input.lua
+++ b/stead/input.lua
@@ -201,7 +201,7 @@ game.action = hook(game.action, function (f, s, cmd, ...)
end
return nil, true -- nothing todo
end
- if f then return f(s, cmd, unpack(arg)) end
+ return f(s, cmd, unpack(arg))
end)
lookup_inp = function()
@@ -231,6 +231,7 @@ input_kbd = function(s, down, key)
input._txt = false
return "kbd_enter"
end
+ return
end
if key == "backspace" then
if input._txt == '' then
@@ -254,7 +255,7 @@ input.key = hook(input.key,
function(f, ...)
local r = input_kbd(unpack(arg))
if r then return r end
- if f then return f(unpack(arg)) end
+ return f(unpack(arg))
end)
function inp(info, txt)
diff --git a/stead/stead.lua b/stead/stead.lua
index 0e03376..6d1f50e 100644
--- a/stead/stead.lua
+++ b/stead/stead.lua
@@ -7,6 +7,8 @@ stead = {
os = os,
call_top = 0,
cctx = { txt = nil, self = nil },
+ nullfn = function()
+ end,
timer = function()
if type(timer) == 'table' and type(timer.callback) == 'function' then
return timer:callback();
@@ -2393,6 +2395,9 @@ end
function hook(o, f)
return function(...)
+ if not o then
+ o = stead.nullfn
+ end
return f(o, unpack(arg))
end
end