| 1333 | }; |
| 1334 | } |
| 1335 | static void IndexFields(lua_State *state, int base, const struct_identity *pstruct, int flags) |
| 1336 | { |
| 1337 | if (pstruct->getParent()) |
| 1338 | IndexFields(state, base, pstruct->getParent(), flags); |
| 1339 | |
| 1340 | auto fields = pstruct->getFields(); |
| 1341 | if (!fields) |
| 1342 | return; |
| 1343 | |
| 1344 | int cnt = lua_rawlen(state, base+3); // field iter table |
| 1345 | |
| 1346 | for (int i = 0; fields[i].mode != struct_field_info::END; ++i) |
| 1347 | { |
| 1348 | // Qualify conflicting field names with the type |
| 1349 | std::string name = fields[i].name; |
| 1350 | |
| 1351 | lua_getfield(state, base+2, name.c_str()); |
| 1352 | if (!lua_isnil(state, -1)) |
| 1353 | name = pstruct->getName() + ("." + name); |
| 1354 | lua_pop(state, 1); |
| 1355 | |
| 1356 | bool add_to_enum = true; |
| 1357 | |
| 1358 | if (!(flags & IndexFieldsFlags::RAW)) |
| 1359 | // Handle the field |
| 1360 | switch (fields[i].mode) |
| 1361 | { |
| 1362 | case struct_field_info::OBJ_METHOD: |
| 1363 | AddMethodWrapper(state, base+1, base+2, name.c_str(), |
| 1364 | (function_identity_base*)fields[i].type); |
| 1365 | continue; |
| 1366 | |
| 1367 | case struct_field_info::CLASS_METHOD: |
| 1368 | continue; |
| 1369 | |
| 1370 | case struct_field_info::POINTER: |
| 1371 | // Skip potentially bad pointers |
| 1372 | if ((fields[i].count & 2) != 0 && fields[i].type) |
| 1373 | add_to_enum = false; |
| 1374 | break; |
| 1375 | |
| 1376 | default: |
| 1377 | break; |
| 1378 | } |
| 1379 | |
| 1380 | // Do not add invalid globals to the enumeration order |
| 1381 | if ((flags & IndexFieldsFlags::GLOBALS) && !*(void**)fields[i].offset) |
| 1382 | add_to_enum = false; |
| 1383 | |
| 1384 | if (add_to_enum || (flags & IndexFieldsFlags::RAW)) |
| 1385 | AssociateId(state, base+3, ++cnt, name.c_str()); |
| 1386 | |
| 1387 | lua_pushlightuserdata(state, (void*)&fields[i]); |
| 1388 | lua_setfield(state, base+2, name.c_str()); |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | static void PushTypeIdentity(lua_State *state, const type_identity *id) |
no test coverage detected