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