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

Function LuaValueToDDF

engine/script/src/script_ddf.cpp:175–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173 }
174
175 static void LuaValueToDDF(lua_State* L, const dmDDF::FieldDescriptor* f,
176 char* buffer, char** data_start, char** data_end, char* pointer_base)
177 {
178 char* where = &buffer[f->m_Offset];
179 bool nil_val = lua_isnil(L, -1);
180 bool array = false;
181 uint32_t n = 1;
182 uint32_t sz = 0;
183
184 if (f->m_Label == dmDDF::LABEL_REPEATED)
185 {
186 luaL_checktype(L, -1, LUA_TTABLE);
187
188 switch (f->m_Type)
189 {
190 case dmDDF::TYPE_INT32:
191 case dmDDF::TYPE_UINT32:
192 sz = sizeof(int32_t);
193 break;
194 case dmDDF::TYPE_UINT64:
195 sz = sizeof(uint64_t);
196 break;
197 case dmDDF::TYPE_BOOL:
198 sz = sizeof(bool);
199 break;
200 case dmDDF::TYPE_FLOAT:
201 sz = sizeof(float);
202 break;
203 case dmDDF::TYPE_STRING:
204 sz = sizeof(const char*);
205 break;
206 case dmDDF::TYPE_ENUM:
207 sz = sizeof(int);
208 break;
209 case dmDDF::TYPE_MESSAGE:
210 {
211 const dmDDF::Descriptor* d = f->m_MessageDescriptor;
212 sz = d->m_Size;
213 break;
214 }
215 default:
216 assert(false);
217 }
218
219 n = lua_objlen(L, -1);
220 *data_start = (char*)DM_ALIGN(*data_start, 16);
221 if (*data_start + n * sz > *data_end)
222 {
223 luaL_error(L, "Message too large.");
224 return;
225 }
226
227 dmDDF::RepeatedField* repeated = (dmDDF::RepeatedField*) where;
228 repeated->m_ArrayCount = n;
229 repeated->m_Array = (uintptr_t)*data_start - (uintptr_t)buffer;
230
231 where = *data_start;
232 *data_start += n * sz;

Callers 1

DoLuaTableToDDFFunction · 0.85

Calls 15

luaL_checktypeFunction · 0.85
lua_objlenFunction · 0.85
luaL_errorFunction · 0.85
lua_rawgetiFunction · 0.85
luaL_checkintegerFunction · 0.85
CheckHashFunction · 0.85
lua_tobooleanFunction · 0.85
luaL_checknumberFunction · 0.85
CheckVector3Function · 0.85
CheckVector4Function · 0.85
CheckQuatFunction · 0.85
CheckMatrix4Function · 0.85

Tested by

no test coverage detected