Move formatting newly-found globals for symbols.xml to lua code.

develop
Alexander Gavrilov 2012-06-21 21:26:25 +04:00
parent f207714d42
commit 752da9ced5
6 changed files with 22 additions and 5 deletions

@ -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()``

@ -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>

@ -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;
}

@ -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;
}

@ -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

@ -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