* Metamethod: __index for enum.attrs */
| 1047 | * Metamethod: __index for enum.attrs |
| 1048 | */ |
| 1049 | static int meta_enum_attr_index(lua_State *state) |
| 1050 | { |
| 1051 | if (!lua_isnumber(state, 2)) |
| 1052 | lua_rawget(state, UPVAL_FIELDTABLE); |
| 1053 | if (!lua_isnumber(state, 2)) |
| 1054 | luaL_error(state, "Invalid index in enum.attrs[]"); |
| 1055 | |
| 1056 | auto id = (enum_identity*)lua_touserdata(state, lua_upvalueindex(2)); |
| 1057 | auto *complex = id->getComplex(); |
| 1058 | |
| 1059 | int64_t idx = lua_tonumber(state, 2); |
| 1060 | if (complex) |
| 1061 | { |
| 1062 | auto it = complex->value_index_map.find(idx); |
| 1063 | if (it != complex->value_index_map.end()) |
| 1064 | idx = int64_t(it->second); |
| 1065 | else |
| 1066 | idx = id->getLastItem() + 1; |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | if (idx < id->getFirstItem() || idx > id->getLastItem()) |
| 1071 | idx = id->getLastItem()+1; |
| 1072 | idx -= id->getFirstItem(); |
| 1073 | } |
| 1074 | |
| 1075 | uint8_t *ptr = (uint8_t*)id->getAttrs(); |
| 1076 | auto atype = id->getAttrType(); |
| 1077 | |
| 1078 | push_object_internal(state, atype, ptr + unsigned(atype->byte_size()*idx)); |
| 1079 | return 1; |
| 1080 | } |
| 1081 | |
| 1082 | /** |
| 1083 | * Metamethod: df.isvalid(obj[,allow_null]) |
nothing calls this directly
no test coverage detected