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

Function LuaGet

engine/gui/src/gui_script.cpp:693–786  ·  view source on GitHub ↗

gets the named property of a specified gui node * * Instead of using specific getters such as gui.get_position or gui.get_scale, * you can use gui.get instead and supply the property as a string or a hash. * While this function is similar to go.get, there are a few more restrictions * when operating in the gui namespace. Most notably, only these explicitly named properties

Source from the content-addressed store, hash-verified

691 * ```
692 */
693 static int LuaGet(lua_State* L)
694 {
695 DM_LUA_STACK_CHECK(L, 1);
696
697 Scene* scene = GuiScriptInstance_Check(L);
698
699 HNode hnode;
700 LuaCheckNodeInternal(L, 1, &hnode);
701
702 dmhash_t property_id = dmScript::CheckHashOrString(L, 2);
703
704 dmGui::PropDesc* pd = dmGui::GetPropertyDesc(property_id);
705 if (pd)
706 {
707 Vector4 base_value = dmGui::GetNodeProperty(scene, hnode, pd->m_Property);
708
709 if (pd->m_Component == 0xff)
710 {
711 if (pd->m_Property == PROPERTY_ROTATION)
712 {
713 dmVMath::Quat r = dmVMath::Quat(base_value);
714 dmScript::PushQuat(L, r);
715 }
716 else
717 {
718 dmScript::PushVector4(L, base_value);
719 }
720 }
721 else
722 {
723 lua_pushnumber(L, base_value.getElem(pd->m_Component));
724 }
725
726 return 1;
727 }
728
729 dmGameObject::LuaToPropertyOptionsResult options_result = {};
730
731 if (lua_gettop(L) >= 3)
732 {
733 dmGameObject::LuaToPropertyOptions(L, 3, &options_result);
734 }
735
736 dmMessage::URL target = {};
737 dmGameObject::PropertyDesc property_desc;
738 dmGameObject::PropertyResult property_res = dmGui::GetMaterialProperty(scene, hnode, property_id, property_desc, &options_result.m_Options) ?
739 dmGameObject::PROPERTY_RESULT_OK : dmGameObject::PROPERTY_RESULT_NOT_FOUND;
740
741 bool is_matrix_type = property_desc.m_Variant.m_Type == dmGameObject::PROPERTY_TYPE_MATRIX4;
742 uint32_t array_size = property_desc.m_ArrayLength;
743 if (is_matrix_type)
744 {
745 array_size = property_desc.m_ArrayLength / 4;
746 }
747
748 if (property_res == dmGameObject::PROPERTY_RESULT_OK && !options_result.m_IndexRequested && property_desc.m_ValueType == dmGameObject::PROP_VALUE_ARRAY && array_size > 1)
749 {
750 lua_newtable(L);

Callers

nothing calls this directly

Calls 15

GuiScriptInstance_CheckFunction · 0.85
LuaCheckNodeInternalFunction · 0.85
CheckHashOrStringFunction · 0.85
GetPropertyDescFunction · 0.85
PushQuatFunction · 0.85
PushVector4Function · 0.85
lua_pushnumberFunction · 0.85
lua_gettopFunction · 0.85
LuaToPropertyOptionsFunction · 0.85
GetMaterialPropertyFunction · 0.85
CheckGetPropertyResultFunction · 0.85
lua_rawsetiFunction · 0.85

Tested by

no test coverage detected