From fa41a27f2643afe8c8b601aab3e2ab3b1403411d Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Sun, 17 Jun 2012 14:26:27 +0400
Subject: [PATCH] Add an api function to get vtable address from version info.
---
LUA_API.rst | 4 ++++
Lua API.html | 3 +++
library/LuaApi.cpp | 12 ++++++++++++
3 files changed, 19 insertions(+)
diff --git a/LUA_API.rst b/LUA_API.rst
index f3d26eaca..1723711d3 100644
--- a/LUA_API.rst
+++ b/LUA_API.rst
@@ -1168,6 +1168,10 @@ and are only documented here for completeness:
Sets the global address ``name``. Returns the value of ``getAddress`` before the change.
+* ``dfhack.internal.getVTable(name)``
+
+ Returns the pre-extracted vtable address ``name``, or *nil*.
+
* ``dfhack.internal.getBase()``
Returns the base address of the process.
diff --git a/Lua API.html b/Lua API.html
index 90e612116..f1bdd17d2 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -1326,6 +1326,9 @@ global environment, persistent between calls to the script.
dfhack.internal.setAddress(name, value)
Sets the global address name. Returns the value of getAddress before the change.
+dfhack.internal.getVTable(name)
+Returns the pre-extracted vtable address name, or nil.
+
dfhack.internal.getBase()
Returns the base address of the process.
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index cdfd47892..631b3c499 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -1080,6 +1080,17 @@ static int internal_setAddress(lua_State *L)
return 1;
}
+static int internal_getVTable(lua_State *L)
+{
+ const char *name = luaL_checkstring(L, 1);
+ uint32_t addr = (uint32_t)Core::getInstance().vinfo->getVTable(name);
+ if (addr)
+ lua_pushnumber(L, addr);
+ else
+ lua_pushnil(L);
+ return 1;
+}
+
static int internal_getMemRanges(lua_State *L)
{
std::vector ranges;
@@ -1200,6 +1211,7 @@ static int internal_diffscan(lua_State *L)
static const luaL_Reg dfhack_internal_funcs[] = {
{ "getAddress", internal_getAddress },
{ "setAddress", internal_setAddress },
+ { "getVTable", internal_getVTable },
{ "getMemRanges", internal_getMemRanges },
{ "memmove", internal_memmove },
{ "memcmp", internal_memcmp },