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

Function RetrieveVarFromScript

engine/gameobject/src/gameobject/comp_script.cpp:949–1010  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

947 }
948
949 static PropertyResult RetrieveVarFromScript(HScriptInstance script_instance,
950 const char* property_name, PropertyType type, dmhash_t* element_ids, bool is_element, uint32_t element_index,
951 PropertyDesc& out_value)
952 {
953 if (type == PROPERTY_TYPE_VECTOR3)
954 {
955 out_value.m_ElementIds[0] = element_ids[0];
956 out_value.m_ElementIds[1] = element_ids[1];
957 out_value.m_ElementIds[2] = element_ids[2];
958 }
959 else if (type == PROPERTY_TYPE_VECTOR4 || type == PROPERTY_TYPE_QUAT)
960 {
961 out_value.m_ElementIds[0] = element_ids[0];
962 out_value.m_ElementIds[1] = element_ids[1];
963 out_value.m_ElementIds[2] = element_ids[2];
964 out_value.m_ElementIds[3] = element_ids[3];
965 }
966
967 lua_State* L = GetLuaState(script_instance);
968
969 int top = lua_gettop(L);
970 (void)top;
971
972 // Only push the script instance if it's not present already
973 dmScript::GetInstance(L);
974 bool push_instance = lua_isnil(L, -1);
975 lua_pop(L, 1);
976 if (push_instance)
977 {
978 lua_rawgeti(L, LUA_REGISTRYINDEX, script_instance->m_InstanceReference);
979 dmScript::SetInstance(L);
980 }
981
982 lua_rawgeti(L, LUA_REGISTRYINDEX, script_instance->m_ScriptDataReference);
983
984 PropertyResult result = PROPERTY_RESULT_NOT_FOUND;
985 lua_pushstring(L, property_name);
986 lua_rawget(L, -2);
987 if (!lua_isnil(L, -1))
988 {
989 result = LuaToVar(L, -1, out_value.m_Variant);
990 if (result == PROPERTY_RESULT_OK)
991 {
992 if (is_element)
993 {
994 out_value.m_Variant = PropertyVar(out_value.m_Variant.m_V4[element_index]);
995 }
996 }
997 }
998
999 lua_pop(L, 2);
1000
1001 if (push_instance)
1002 {
1003 lua_pushnil(L);
1004 dmScript::SetInstance(L);
1005 }
1006

Callers 2

CompScriptGetPropertyFunction · 0.85

Calls 11

lua_gettopFunction · 0.85
lua_rawgetiFunction · 0.85
SetInstanceFunction · 0.85
lua_pushstringFunction · 0.85
lua_rawgetFunction · 0.85
LuaToVarFunction · 0.85
lua_pushnilFunction · 0.85
GetLuaStateFunction · 0.70
GetInstanceFunction · 0.50
PropertyVarClass · 0.50
assertFunction · 0.50

Tested by

no test coverage detected