Added getKeys method to lua offsetgroup and a way to cast versioninfo to offsetgroup

develop
Warmist 2011-12-24 16:00:43 +02:00
parent 0bc41ccb10
commit 71e2321fef
2 changed files with 42 additions and 6 deletions

@ -28,6 +28,7 @@ public:
int getName(lua_State *L);
int getFullName(lua_State *L);
int getParent(lua_State *L);
int getKeys(lua_State *L);
DEF_LUNE(OffsetGroup);
};

@ -96,6 +96,29 @@ int OffsetGroup::getParent(lua_State *L)
st.pcall(2,1);
return 1;
}
int OffsetGroup::getKeys(lua_State *L)
{
const char* invalids[]={"notset","invalid","valid"};
const char* keytypes[]={"offset","address","hexval","string","group"};
lua::state st(L);
std::vector<DFHack::OffsetKey> t= p->getKeys();
st.newtable();
for(size_t i=0;i<t.size();i++)
{
st.push(i);
st.newtable();
st.push(invalids[t[i].inval]);
st.setfield("invalid");
st.push(t[i].key);
st.setfield("key");
st.push(keytypes[t[i].keytype]);//maybe use int...
st.setfield("keytype");
st.settable();
}
return 1;
}
}
IMP_LUNE(lua::OffsetGroup,OffsetGroup);
LUNE_METHODS_START(lua::OffsetGroup)
@ -112,6 +135,7 @@ LUNE_METHODS_START(lua::OffsetGroup)
method(lua::OffsetGroup,getName),
method(lua::OffsetGroup,getFullName),
method(lua::OffsetGroup,getParent),
method(lua::OffsetGroup,getKeys),
LUNE_METHODS_END();
// VersionInfo Stuff
static int __lua_getMD5(lua_State *S)
@ -326,12 +350,23 @@ static int __lua_getHexValue(lua_State *S)
static int __lua_getGroup(lua_State *S)
{
lua::state st(S);
if(st.as<std::string>(1)=="") //if no argument, return version info as a groupoffset (dynamic cast)
{
st.getglobal("OffsetGroup");
st.getfield("new");
st.getglobal("OffsetGroup");
st.pushlightuserdata(dynamic_cast<DFHack::OffsetGroup*>(DFHack::Core::getInstance().vinfo));
st.pcall(2,1);
}
else
{
DFHack::OffsetGroup* t= DFHack::Core::getInstance().vinfo->getGroup(st.as<std::string>(1));
st.getglobal("OffsetGroup");
st.getfield("new");
st.getglobal("OffsetGroup");
st.pushlightuserdata(t);
st.pcall(2,1);
}
return 1;
}
static int __lua_getParent(lua_State *S)