* Traverse a Lua table */
| 1250 | * Traverse a Lua table |
| 1251 | */ |
| 1252 | int32 TraverseTable(lua_State *L, int32 Index, void *Userdata, bool(*TraverseWorker)(lua_State*, void*)) |
| 1253 | { |
| 1254 | if (Index < 0 && Index > LUA_REGISTRYINDEX) |
| 1255 | { |
| 1256 | int32 Top = lua_gettop(L); |
| 1257 | Index = Top + Index + 1; |
| 1258 | } |
| 1259 | int32 Type = lua_type(L, Index); |
| 1260 | if (Type == LUA_TTABLE) |
| 1261 | { |
| 1262 | if (!lua_checkstack(L, 2)) |
| 1263 | { |
| 1264 | return INDEX_NONE; |
| 1265 | } |
| 1266 | |
| 1267 | int32 NumElements = 0; |
| 1268 | lua_pushnil(L); |
| 1269 | while (lua_next(L, Index) != 0) |
| 1270 | { |
| 1271 | if (TraverseWorker) |
| 1272 | { |
| 1273 | bool b = TraverseWorker(L, Userdata); |
| 1274 | if (b) |
| 1275 | { |
| 1276 | ++NumElements; |
| 1277 | } |
| 1278 | } |
| 1279 | lua_pop(L, 1); |
| 1280 | } |
| 1281 | return NumElements; |
| 1282 | } |
| 1283 | return INDEX_NONE; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * __index meta methods for enum |
no test coverage detected