From 752da9ced5ce2df8cc9638cbf75a769325540e31 Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Thu, 21 Jun 2012 21:26:25 +0400
Subject: [PATCH] Move formatting newly-found globals for symbols.xml to lua
code.
---
LUA_API.rst | 1 +
Lua API.html | 3 ++-
library/LuaApi.cpp | 6 +++---
library/LuaTools.cpp | 5 ++++-
library/include/ColorText.h | 2 ++
library/lua/memscan.lua | 10 ++++++++++
6 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/LUA_API.rst b/LUA_API.rst
index 9515690eb..5136bba57 100644
--- a/LUA_API.rst
+++ b/LUA_API.rst
@@ -451,6 +451,7 @@ Currently it defines the following features:
* ``dfhack.color([color])``
Sets the current output color. If color is *nil* or *-1*, resets to default.
+ Returns the previous color value.
* ``dfhack.is_interactive()``
diff --git a/Lua API.html b/Lua API.html
index 84d13e2f0..1c4dc4059 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -734,7 +734,8 @@ works with DFHack output infrastructure.
Same as println; intended for errors. Uses red color and logs to stderr.log.
dfhack.color([color])
-Sets the current output color. If color is nil or -1, resets to default.
+Sets the current output color. If color is nil or -1, resets to default.
+Returns the previous color value.
dfhack.is_interactive()
Checks if the thread can access the interactive console and returns true or false.
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index 092404e33..b0a085eca 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -1074,9 +1074,9 @@ static int internal_setAddress(lua_State *L)
}
// Print via printerr, so that it is definitely logged to stderr.log.
- addr -= Core::getInstance().vinfo->getRebaseDelta();
- std::string msg = stl_sprintf("", name.c_str(), addr);
- dfhack_printerr(L, msg);
+ uint32_t iaddr = addr - Core::getInstance().vinfo->getRebaseDelta();
+ fprintf(stderr, "Setting global '%s' to %x (%x)\n", name.c_str(), addr, iaddr);
+ fflush(stderr);
return 1;
}
diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp
index 752c341b2..48244dedf 100644
--- a/library/LuaTools.cpp
+++ b/library/LuaTools.cpp
@@ -256,8 +256,11 @@ static int lua_dfhack_color(lua_State *S)
luaL_argerror(S, 1, "invalid color value");
color_ostream *out = Lua::GetOutput(S);
- if (out)
+ if (out) {
+ lua_pushinteger(S, (int)out->color());
out->color(color_ostream::color_value(cv));
+ return 1;
+ }
return 0;
}
diff --git a/library/include/ColorText.h b/library/include/ColorText.h
index 105832efd..0cc286dcf 100644
--- a/library/include/ColorText.h
+++ b/library/include/ColorText.h
@@ -111,6 +111,8 @@ namespace DFHack
void printerr(const char *format, ...);
void vprinterr(const char *format, va_list args);
+ /// Get color
+ color_value color() { return cur_color; }
/// Set color (ANSI color number)
void color(color_value c);
/// Reset color to default
diff --git a/library/lua/memscan.lua b/library/lua/memscan.lua
index 4cf8d41c8..92a3e3e80 100644
--- a/library/lua/memscan.lua
+++ b/library/lua/memscan.lua
@@ -252,6 +252,16 @@ function found_offset(name,val)
end
else
dfhack.internal.setAddress(name, val)
+
+ local ival = val - dfhack.internal.getRebaseDelta()
+ local entry = string.format("\n", name, ival)
+
+ local ccolor = dfhack.color(COLOR_LIGHTGREEN)
+ dfhack.print(entry)
+ dfhack.color(ccolor)
+
+ io.stdout:write(entry)
+ io.stdout:flush()
end
end