| 1683 | } |
| 1684 | |
| 1685 | bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) { |
| 1686 | ERR_FAIL_NULL_V(p_object, false); |
| 1687 | |
| 1688 | ClassInfo *type = classes.getptr(p_object->get_class_name()); |
| 1689 | ClassInfo *check = type; |
| 1690 | while (check) { |
| 1691 | const PropertySetGet *psg = check->property_setget.getptr(p_property); |
| 1692 | if (psg) { |
| 1693 | if (!psg->getter) { |
| 1694 | return true; //return true but do nothing |
| 1695 | } |
| 1696 | |
| 1697 | if (psg->index >= 0) { |
| 1698 | Variant index = psg->index; |
| 1699 | const Variant *arg[1] = { &index }; |
| 1700 | Callable::CallError ce; |
| 1701 | const Variant value = p_object->callp(psg->getter, arg, 1, ce); |
| 1702 | r_value = (ce.error == Callable::CallError::CALL_OK) ? value : Variant(); |
| 1703 | |
| 1704 | } else { |
| 1705 | Callable::CallError ce; |
| 1706 | if (psg->_getptr) { |
| 1707 | r_value = psg->_getptr->call(p_object, nullptr, 0, ce); |
| 1708 | } else { |
| 1709 | const Variant value = p_object->callp(psg->getter, nullptr, 0, ce); |
| 1710 | r_value = (ce.error == Callable::CallError::CALL_OK) ? value : Variant(); |
| 1711 | } |
| 1712 | } |
| 1713 | return true; |
| 1714 | } |
| 1715 | |
| 1716 | const int64_t *c = check->constant_map.getptr(p_property); //constants count |
| 1717 | if (c) { |
| 1718 | r_value = *c; |
| 1719 | return true; |
| 1720 | } |
| 1721 | |
| 1722 | if (check->method_map.has(p_property)) { //methods count |
| 1723 | r_value = Callable(p_object, p_property); |
| 1724 | return true; |
| 1725 | } |
| 1726 | |
| 1727 | if (check->signal_map.has(p_property)) { //signals count |
| 1728 | r_value = Signal(p_object, p_property); |
| 1729 | return true; |
| 1730 | } |
| 1731 | |
| 1732 | check = check->inherits_ptr; |
| 1733 | } |
| 1734 | |
| 1735 | // The "free()" method is special, so we assume it exists and return a Callable. |
| 1736 | if (p_property == CoreStringName(free_)) { |
| 1737 | r_value = Callable(p_object, p_property); |
| 1738 | return true; |
| 1739 | } |
| 1740 | |
| 1741 | return false; |
| 1742 | } |