diff options
| author | Alexander Gavrilov | 2012-04-17 12:15:45 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-04-17 12:15:45 +0400 |
| commit | 378a1fb914655569c8dfa4dffcda9acb6f3931bf (patch) | |
| tree | e4abe98ec6b7c8b437907e691f00049ecefd3f20 /library/LuaTypes.cpp | |
| parent | 3beb2ebf25b94736a3823c317f603a8fc8bd0f53 (diff) | |
| download | dfhack-378a1fb914655569c8dfa4dffcda9acb6f3931bf.tar.gz dfhack-378a1fb914655569c8dfa4dffcda9acb6f3931bf.tar.bz2 dfhack-378a1fb914655569c8dfa4dffcda9acb6f3931bf.tar.xz | |
Support the '#' string as index for wrapper vector insert at end.
Diffstat (limited to 'library/LuaTypes.cpp')
| -rw-r--r-- | library/LuaTypes.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index c5ffe0f6..2cfe8a84 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -733,8 +733,18 @@ static int lookup_container_field(lua_State *state, int field, const char *mode * Index verification: number and in range. */ static int check_container_index(lua_State *state, int len, - int fidx, int iidx, const char *mode) + int fidx, int iidx, const char *mode, + bool is_insert = false) { + if (is_insert && len >= 0) + { + if (lua_type(state, iidx) == LUA_TSTRING + && strcmp(lua_tostring(state, iidx), "#") == 0) + return len; + + len++; + } + if (!lua_isnumber(state, iidx)) field_error(state, fidx, "invalid index", mode); @@ -867,8 +877,7 @@ static int method_container_insert(lua_State *state) auto id = (container_identity*)lua_touserdata(state, UPVAL_CONTAINER_ID); int len = id->lua_item_count(state, ptr, container_identity::COUNT_LEN); - if (len >= 0) len++; - int idx = check_container_index(state, len, UPVAL_METHOD_NAME, 2, "call"); + int idx = check_container_index(state, len, UPVAL_METHOD_NAME, 2, "call", true); if (!id->lua_insert(state, UPVAL_METHOD_NAME, ptr, idx, 3)) field_error(state, UPVAL_METHOD_NAME, "not supported", "call"); |
