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

Function ResolveInstance

engine/gameobject/src/gameobject/gameobject_script.cpp:404–424  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

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 {

Callers 15

Script_GetPositionFunction · 0.85
Script_GetRotationFunction · 0.85
Script_GetScaleFunction · 0.85
Script_GetScaleUniformFunction · 0.85
Script_SetPositionFunction · 0.85
Script_SetRotationFunction · 0.85
Script_SetScaleFunction · 0.85
Script_SetScaleXYFunction · 0.85
Script_GetParentFunction · 0.85
Script_GetWorldPositionFunction · 0.85
Script_GetWorldRotationFunction · 0.85
Script_GetWorldScaleFunction · 0.85

Calls 6

ScriptInstance_CheckFunction · 0.85
lua_gettopFunction · 0.85
GetMessageSocketFunction · 0.85
luaL_errorFunction · 0.85
ResolveURLFunction · 0.70

Tested by

no test coverage detected