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

Function FactoryComp_Create

engine/gamesys/src/gamesys/scripts/script_factory.cpp:276–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

274 }
275
276 static int FactoryComp_Create(lua_State* L)
277 {
278 int top = lua_gettop(L);
279
280 dmGameObject::HInstance sender_instance = dmScript::CheckGOInstance(L);
281 dmGameObject::HCollection collection = dmGameObject::GetCollection(sender_instance);
282
283 HFactoryWorld world;
284 HFactoryComponent component;
285 dmMessage::URL receiver;
286 dmScript::GetComponentFromLua(L, 1, FACTORY_EXT, (dmGameObject::HComponentWorld*)&world, (dmGameObject::HComponent*)&component, &receiver);
287
288 dmVMath::Point3 position;
289 if (top >= 2 && !lua_isnil(L, 2))
290 {
291 position = dmVMath::Point3(*dmScript::CheckVector3(L, 2));
292 }
293 else
294 {
295 position = dmGameObject::GetWorldPosition(sender_instance);
296 }
297 dmVMath::Quat rotation;
298 if (top >= 3 && !lua_isnil(L, 3))
299 {
300 rotation = *dmScript::CheckQuat(L, 3);
301 }
302 else
303 {
304 rotation = dmGameObject::GetWorldRotation(sender_instance);
305 }
306
307 dmGameObject::HPropertyContainer properties = 0;
308 if (top >= 4 && lua_istable(L, 4))
309 {
310 properties = dmGameObject::PropertyContainerCreateFromLua(L, 4);
311 }
312
313 dmVMath::Vector3 scale;
314 if (top >= 5 && !lua_isnil(L, 5))
315 {
316 // We check for zero in the ToTransform/ResetScale in transform.h
317 dmVMath::Vector3* v = dmScript::ToVector3(L, 5);
318 if (v != 0)
319 {
320 scale = *v;
321 }
322 else
323 {
324 float val = luaL_checknumber(L, 5);
325 scale = dmVMath::Vector3(val, val, val);
326 }
327 }
328 else
329 {
330 scale = dmGameObject::GetWorldScale(sender_instance);
331 }
332
333 dmhash_t id = dmGameObject::CreateInstanceId();

Callers

nothing calls this directly

Calls 15

lua_gettopFunction · 0.85
CheckGOInstanceFunction · 0.85
GetCollectionFunction · 0.85
CheckVector3Function · 0.85
CheckQuatFunction · 0.85
ToVector3Function · 0.85
luaL_checknumberFunction · 0.85
GetWorldScaleFunction · 0.85
CreateInstanceIdFunction · 0.85
GetInstanceFromLuaFunction · 0.85

Tested by

no test coverage detected