MCPcopy Create free account
hub / github.com/DavidColson/Polybox / AllocUserData

Function AllocUserData

source/userdata.cpp:93–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91// ***********************************************************************
92
93UserData* AllocUserData(lua_State* L, Type type, i32 width, i32 height) {
94 i32 typeSize = 0;
95 switch (type) {
96 case Type::Float32: typeSize = sizeof(f32); break;
97 case Type::Int32: typeSize = sizeof(i32); break;
98 case Type::Int16: typeSize = sizeof(i16); break;
99 case Type::Uint8: typeSize = sizeof(u8); break;
100 }
101
102 i32 bufSize = width * height * typeSize;
103 UserData* pUserData = (UserData*)lua_newuserdata(L, sizeof(UserData) + bufSize);
104 memset(pUserData, 0, sizeof(UserData) + bufSize);
105 pUserData->pData = (u8*)pUserData + sizeof(UserData);
106 pUserData->width = width;
107 pUserData->height = height;
108 pUserData->type = type;
109 pUserData->img.id = SG_INVALID_ID;
110 pUserData->dirty = false;
111 pUserData->dynamic = false;
112
113 luaL_getmetatable(L, "UserData");
114 lua_setmetatable(L, -2);
115 return pUserData;
116}
117
118// ***********************************************************************
119

Callers 8

ParseJsonNodeRecursivelyFunction · 0.85
ImportGltfFunction · 0.85
NewUserDataFunction · 0.85
NewVecFunction · 0.85
NewQuatFunction · 0.85
LuaGetMatrixFunction · 0.85
ParseUserDataFunction · 0.85
ParseCborValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected