| 1761 | } |
| 1762 | |
| 1763 | bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { |
| 1764 | { |
| 1765 | HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = script->member_indices.find(p_name); |
| 1766 | if (E) { |
| 1767 | if (likely(script->valid) && E->value.getter) { |
| 1768 | Callable::CallError err; |
| 1769 | const Variant ret = const_cast<GDScriptInstance *>(this)->callp(E->value.getter, nullptr, 0, err); |
| 1770 | r_ret = (err.error == Callable::CallError::CALL_OK) ? ret : Variant(); |
| 1771 | return true; |
| 1772 | } |
| 1773 | r_ret = members[E->value.index]; |
| 1774 | return true; |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | const GDScript *sptr = script.ptr(); |
| 1779 | while (sptr) { |
| 1780 | { |
| 1781 | HashMap<StringName, Variant>::ConstIterator E = sptr->constants.find(p_name); |
| 1782 | if (E) { |
| 1783 | r_ret = E->value; |
| 1784 | return true; |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | { |
| 1789 | HashMap<StringName, GDScript::MemberInfo>::ConstIterator E = sptr->static_variables_indices.find(p_name); |
| 1790 | if (E) { |
| 1791 | if (likely(sptr->valid) && E->value.getter) { |
| 1792 | Callable::CallError ce; |
| 1793 | const Variant ret = const_cast<GDScript *>(sptr)->callp(E->value.getter, nullptr, 0, ce); |
| 1794 | r_ret = (ce.error == Callable::CallError::CALL_OK) ? ret : Variant(); |
| 1795 | return true; |
| 1796 | } |
| 1797 | r_ret = sptr->static_variables[E->value.index]; |
| 1798 | return true; |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | { |
| 1803 | HashMap<StringName, MethodInfo>::ConstIterator E = sptr->_signals.find(p_name); |
| 1804 | if (E) { |
| 1805 | r_ret = Signal(owner, E->key); |
| 1806 | return true; |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | if (likely(sptr->valid)) { |
| 1811 | HashMap<StringName, GDScriptFunction *>::ConstIterator E = sptr->member_functions.find(p_name); |
| 1812 | if (E) { |
| 1813 | if (sptr->rpc_config.has(p_name)) { |
| 1814 | r_ret = Callable(memnew(GDScriptRPCCallable(owner, E->key))); |
| 1815 | } else { |
| 1816 | r_ret = Callable(owner, E->key); |
| 1817 | } |
| 1818 | return true; |
| 1819 | } |
| 1820 | } |