MCPcopy Create free account
hub / github.com/defold/defold / GetMetadata

Function GetMetadata

engine/gamesys/src/gamesys/scripts/script_buffer.cpp:1060–1122  ·  view source on GitHub ↗

retrieve a metadata entry from a buffer * * Get a named metadata entry from a buffer along with its type. * * @name buffer.get_metadata * @param buf [type:buffer] the buffer to get the metadata from * @param metadata_name [type:hash|string] name of the metadata entry * @return values [type:table|nil] table of metadata values or `nil` if the entry does not exist

Source from the content-addressed store, hash-verified

1058 * ```
1059 */
1060 static int GetMetadata(lua_State* L)
1061 {
1062 DM_LUA_STACK_CHECK(L, 2);
1063
1064 // get buffer
1065 dmBuffer::HBuffer hbuffer = dmScript::CheckBufferUnpack(L, 1);
1066
1067 // get metadata entry name
1068 dmhash_t entry_name = dmScript::CheckHashOrString(L, 2);
1069
1070 uint32_t count;
1071 dmBuffer::ValueType valueType;
1072 void* values;
1073 dmBuffer::Result r = dmBuffer::GetMetaData(hbuffer, entry_name, &values, &count, &valueType);
1074 if ( r == dmBuffer::RESULT_METADATA_MISSING)
1075 {
1076 lua_pushnil(L); // nil for metadata entry
1077 lua_pushnil(L); // nil for numbertype
1078 return 2;
1079 }
1080 if ( r != dmBuffer::RESULT_OK )
1081 {
1082 return DM_LUA_ERROR("error getting metadata for buffer: %s", dmBuffer::GetResultString(r));
1083 }
1084
1085 lua_newtable(L);
1086 #define DM_ARRAY_TO_LUA_TABLE(_T_) ArrayToLuaTable<_T_>(L, (_T_*) values, count, valueType)
1087 switch (valueType)
1088 {
1089 case dmBuffer::VALUE_TYPE_FLOAT32:
1090 DM_ARRAY_TO_LUA_TABLE(float);
1091 break;
1092 case dmBuffer::VALUE_TYPE_UINT8:
1093 DM_ARRAY_TO_LUA_TABLE(uint8_t);
1094 break;
1095 case dmBuffer::VALUE_TYPE_UINT16:
1096 DM_ARRAY_TO_LUA_TABLE(uint16_t);
1097 break;
1098 case dmBuffer::VALUE_TYPE_UINT32:
1099 DM_ARRAY_TO_LUA_TABLE(uint32_t);
1100 break;
1101 case dmBuffer::VALUE_TYPE_INT8:
1102 DM_ARRAY_TO_LUA_TABLE(int8_t);
1103 break;
1104 case dmBuffer::VALUE_TYPE_INT16:
1105 DM_ARRAY_TO_LUA_TABLE(int16_t);
1106 break;
1107 case dmBuffer::VALUE_TYPE_INT32:
1108 DM_ARRAY_TO_LUA_TABLE(int32_t);
1109 break;
1110 case dmBuffer::VALUE_TYPE_UINT64:
1111 case dmBuffer::VALUE_TYPE_INT64:
1112 return DM_LUA_ERROR("retrieving 64 bit integer metadata is not supported");
1113 break;
1114 default:
1115 // we shouldn't reach this point
1116 return DM_LUA_ERROR("invalid value type supplied: %d", valueType);
1117 }

Callers

nothing calls this directly

Calls 6

CheckBufferUnpackFunction · 0.85
CheckHashOrStringFunction · 0.85
GetMetaDataFunction · 0.85
lua_pushnilFunction · 0.85
GetResultStringFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected