* Metamethod: represent a DF object reference as string. */
| 1018 | * Metamethod: represent a DF object reference as string. |
| 1019 | */ |
| 1020 | static int meta_ptr_tostring(lua_State *state) |
| 1021 | { |
| 1022 | uint8_t *ptr = get_object_addr(state, 1, 0, "access"); |
| 1023 | |
| 1024 | bool has_length = false; |
| 1025 | uint64_t length = 0; |
| 1026 | auto *cid = dynamic_cast<const df::container_identity*>(get_object_identity(state, 1, "__tostring()", true, true)); |
| 1027 | |
| 1028 | if (cid && (cid->type() == IDTYPE_CONTAINER || cid->type() == IDTYPE_STL_PTR_VECTOR)) |
| 1029 | { |
| 1030 | has_length = true; |
| 1031 | length = cid->lua_item_count(state, ptr, container_identity::COUNT_LEN); |
| 1032 | } |
| 1033 | |
| 1034 | lua_getfield(state, UPVAL_METATABLE, "__metatable"); |
| 1035 | const char *cname = lua_tostring(state, -1); |
| 1036 | |
| 1037 | auto str = has_length ? |
| 1038 | fmt::format("<{}[{}]: {}>", cname, length, static_cast<void*>(ptr)) : |
| 1039 | fmt::format("<{}: {}>", cname, static_cast<void*>(ptr)); |
| 1040 | |
| 1041 | lua_pushlstring(state, str.data(), str.size()); |
| 1042 | |
| 1043 | return 1; |
| 1044 | } |
| 1045 | |
| 1046 | /** |
| 1047 | * Metamethod: __index for enum.attrs |
nothing calls this directly
no test coverage detected