diff options
| author | Alexander Gavrilov | 2012-04-20 13:04:03 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-20 13:04:03 +0400 |
| commit | d95cc3435fe249e1c86e5af36b8a10e9009edd97 (patch) | |
| tree | e20205016f43c95d15540e2ae49ba27efd3ce1c7 /library/LuaWrapper.cpp | |
| parent | 0b32d374db8a58547d554d758e4e77ad850f54c5 (diff) | |
| download | dfhack-d95cc3435fe249e1c86e5af36b8a10e9009edd97.tar.gz dfhack-d95cc3435fe249e1c86e5af36b8a10e9009edd97.tar.bz2 dfhack-d95cc3435fe249e1c86e5af36b8a10e9009edd97.tar.xz | |
Fix lua wrapper sizeof for static arrays.
Since it actually depends on the element type, it is more tricky.
Diffstat (limited to 'library/LuaWrapper.cpp')
| -rw-r--r-- | library/LuaWrapper.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/library/LuaWrapper.cpp b/library/LuaWrapper.cpp index 1c3b61c1..0b958f37 100644 --- a/library/LuaWrapper.cpp +++ b/library/LuaWrapper.cpp @@ -542,10 +542,23 @@ static int meta_sizeof(lua_State *state) return 2; } - type_identity *id = get_object_identity(state, 1, "df.sizeof()", true); + type_identity *id = get_object_identity(state, 1, "df.sizeof()", true, true); - lua_pushinteger(state, id->byte_size()); + // Static arrays need special handling + if (id->type() == IDTYPE_BUFFER) + { + auto buf = (df::buffer_container_identity*)id; + type_identity *item = buf->getItemType(); + int count = buf->getSize(); + + fetch_container_details(state, lua_gettop(state), &item, &count); + + lua_pushinteger(state, item->byte_size() * count); + } + else + lua_pushinteger(state, id->byte_size()); + // Add the address if (lua_isuserdata(state, 1)) { lua_pushnumber(state, (size_t)get_object_ref(state, 1)); |
