| 866 | // Utility |
| 867 | |
| 868 | Variant VariantUtilityFunctions::weakref(Callable::CallError &r_error, const Variant &obj) { |
| 869 | if (obj.get_type() == Variant::OBJECT) { |
| 870 | r_error.error = Callable::CallError::CALL_OK; |
| 871 | if (obj.is_ref_counted()) { |
| 872 | Ref<WeakRef> wref = memnew(WeakRef); |
| 873 | Ref<RefCounted> r = obj; |
| 874 | if (r.is_valid()) { |
| 875 | wref->set_ref(r); |
| 876 | } |
| 877 | return wref; |
| 878 | } else { |
| 879 | Ref<WeakRef> wref = memnew(WeakRef); |
| 880 | Object *o = obj.get_validated_object(); |
| 881 | if (o) { |
| 882 | wref->set_obj(o); |
| 883 | } |
| 884 | return wref; |
| 885 | } |
| 886 | } else if (obj.get_type() == Variant::NIL) { |
| 887 | r_error.error = Callable::CallError::CALL_OK; |
| 888 | Ref<WeakRef> wref = memnew(WeakRef); |
| 889 | return wref; |
| 890 | } else { |
| 891 | r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; |
| 892 | r_error.argument = 0; |
| 893 | r_error.expected = Variant::OBJECT; |
| 894 | return Variant(); |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | int64_t VariantUtilityFunctions::_typeof(const Variant &obj) { |
| 899 | return obj.get_type(); |
nothing calls this directly
no test coverage detected