summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-06-21 21:26:25 +0400
committerAlexander Gavrilov2012-06-21 21:26:25 +0400
commit752da9ced5ce2df8cc9638cbf75a769325540e31 (patch)
tree0bbf1c817e4c3f663bfe06e2ab3f2c05262952ff
parentf207714d4225e729fa43d04048d595ad6954521d (diff)
downloaddfhack-752da9ced5ce2df8cc9638cbf75a769325540e31.tar.gz
dfhack-752da9ced5ce2df8cc9638cbf75a769325540e31.tar.bz2
dfhack-752da9ced5ce2df8cc9638cbf75a769325540e31.tar.xz
Move formatting newly-found globals for symbols.xml to lua code.
-rw-r--r--LUA_API.rst1
-rw-r--r--Lua API.html3
-rw-r--r--library/LuaApi.cpp6
-rw-r--r--library/LuaTools.cpp5
-rw-r--r--library/include/ColorText.h2
-rw-r--r--library/lua/memscan.lua10
6 files changed, 22 insertions, 5 deletions
diff --git a/LUA_API.rst b/LUA_API.rst
index 9515690e..5136bba5 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 84d13e2f..1c4dc405 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -734,7 +734,8 @@ works with DFHack output infrastructure.</p>
<p>Same as println; intended for errors. Uses red color and logs to stderr.log.</p>
</li>
<li><p class="first"><tt class="docutils literal"><span class="pre">dfhack.color([color])</span></tt></p>
-<p>Sets the current output color. If color is <em>nil</em> or <em>-1</em>, resets to default.</p>
+<p>Sets the current output color. If color is <em>nil</em> or <em>-1</em>, resets to default.
+Returns the previous color value.</p>
</li>
<li><p class="first"><tt class="docutils literal">dfhack.is_interactive()</tt></p>
<p>Checks if the thread can access the interactive console and returns <em>true</em> or <em>false</em>.</p>
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index 092404e3..b0a085ec 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("<global-address name='%s' value='0x%x'/>", 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 752c341b..48244ded 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 105832ef..0cc286dc 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 4cf8d41c..92a3e3e8 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("<global-address name='%s' value='0x%x'/>\n", name, ival)
+
+ local ccolor = dfhack.color(COLOR_LIGHTGREEN)
+ dfhack.print(entry)
+ dfhack.color(ccolor)
+
+ io.stdout:write(entry)
+ io.stdout:flush()
end
end