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

Function SetMetadata

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

set a metadata entry on a buffer * * Creates or updates a metadata array entry on a buffer. * * [icon:attention] The value type and count given when updating the entry should match those used when first creating it. * * @name buffer.set_metadata * @param buf [type:buffer] the buffer to set the metadata on * @param metadata_name [type:hash|string] name of the

Source from the content-addressed store, hash-verified

944 * ```
945 */
946 static int SetMetadata(lua_State* L)
947 {
948 DM_LUA_STACK_CHECK(L, 0);
949
950 // get buffer
951 dmBuffer::HBuffer hbuffer = dmScript::CheckBufferUnpack(L, 1);
952
953 // get metadata entry name
954 dmhash_t entry_name = dmScript::CheckHashOrString(L, 2);
955
956 // get number type
957 dmBuffer::ValueType valueType = (dmBuffer::ValueType) luaL_checkinteger(L, 4);
958
959 // get array of values
960 luaL_checktype(L, 3, LUA_TTABLE);
961 uint32_t count = lua_objlen(L, 3);
962 if (count > 0)
963 {
964 // validate valuetype early
965 if (valueType < 0 || valueType >= dmBuffer::MAX_VALUE_TYPE_COUNT)
966 {
967 return DM_LUA_ERROR("invalid metadata value type supplied: %ld", (long) valueType);
968 }
969 if (valueType == dmBuffer::VALUE_TYPE_UINT64 || valueType == dmBuffer::VALUE_TYPE_INT64)
970 {
971 return DM_LUA_ERROR("64 bit integer metadata are not supported.");
972 }
973
974 void* values = 0;
975 lua_pushvalue(L, 3);
976
977 #define DM_LUA_TABLE_TO_ARRAY(_T_) values = (void*) LuaTableToArray<_T_>(L, count, valueType)
978 switch(valueType)
979 {
980 case dmBuffer::VALUE_TYPE_FLOAT32:
981 DM_LUA_TABLE_TO_ARRAY(float);
982 break;
983 case dmBuffer::VALUE_TYPE_UINT8:
984 DM_LUA_TABLE_TO_ARRAY(uint8_t);
985 break;
986 case dmBuffer::VALUE_TYPE_UINT16:
987 DM_LUA_TABLE_TO_ARRAY(uint16_t);
988 break;
989 case dmBuffer::VALUE_TYPE_UINT32:
990 DM_LUA_TABLE_TO_ARRAY(uint32_t);
991 break;
992 case dmBuffer::VALUE_TYPE_INT8:
993 DM_LUA_TABLE_TO_ARRAY(int8_t);
994 break;
995 case dmBuffer::VALUE_TYPE_INT16:
996 DM_LUA_TABLE_TO_ARRAY(int16_t);
997 break;
998 case dmBuffer::VALUE_TYPE_INT32:
999 DM_LUA_TABLE_TO_ARRAY(int32_t);
1000 break;
1001 default:break;
1002 }
1003 #undef DM_LUA_TABLE_TO_ARRAY

Callers

nothing calls this directly

Calls 9

CheckBufferUnpackFunction · 0.85
CheckHashOrStringFunction · 0.85
luaL_checkintegerFunction · 0.85
luaL_checktypeFunction · 0.85
lua_objlenFunction · 0.85
lua_pushvalueFunction · 0.85
SetMetaDataFunction · 0.85
freeFunction · 0.85
GetResultStringFunction · 0.85

Tested by

no test coverage detected