* Get instance utility function helper. * The function will use the default "this" instance by default * but if lua_gettop(L) == instance_arg, i.e. an instance reference is specified, * the argument instance_arg will be resolved to an instance. The function * only accepts instances in "this" collection. Otherwise a lua-error will be raised. * @param L lua state * @par
| 402 | * @return instance handler |
| 403 | */ |
| 404 | static Instance* ResolveInstance(lua_State* L, int instance_arg) |
| 405 | { |
| 406 | ScriptInstance* i = ScriptInstance_Check(L); |
| 407 | Instance* instance = i->m_Instance; |
| 408 | if (lua_gettop(L) == instance_arg && !lua_isnil(L, instance_arg)) { |
| 409 | dmMessage::URL receiver; |
| 410 | dmScript::ResolveURL(L, instance_arg, &receiver, 0x0); |
| 411 | if (receiver.m_Socket != dmGameObject::GetMessageSocket(i->m_Instance->m_Collection->m_HCollection)) |
| 412 | { |
| 413 | luaL_error(L, "function called can only access instances within the same collection."); |
| 414 | } |
| 415 | |
| 416 | instance = GetInstanceFromIdentifier(instance->m_Collection->m_HCollection, receiver.m_Path); |
| 417 | if (!instance) |
| 418 | { |
| 419 | luaL_error(L, "Instance %s not found", lua_tostring(L, instance_arg)); |
| 420 | return 0; // Actually never reached |
| 421 | } |
| 422 | } |
| 423 | return instance; |
| 424 | } |
| 425 | |
| 426 | void GetComponentFromLua(lua_State* L, int index, HCollection collection, const char* component_ext, dmGameObject::HComponent* out_component, dmMessage::URL* url, dmGameObject::HComponentWorld* out_world) |
| 427 | { |
no test coverage detected