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
| 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 |
nothing calls this directly
no test coverage detected