Skip to content

Commit 64cdaf5

Browse files
authored
Add missing core Object methods. (#792)
1 parent 32c5e4c commit 64cdaf5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

kt/godot-library/godot-core-library/src/main/kotlin/godot/core/KtObject.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ abstract class KtObject : NativeWrapper {
5555

5656
protected abstract fun new(scriptIndex: Int)
5757

58+
open fun _get(property: StringName): Any = throw NotImplementedError("_get is not implemented for Object")
59+
open fun _getPropertyList(): VariantArray<Dictionary<Any, Any>> = throw NotImplementedError("_getPropertyList is not implemented for Object")
60+
open fun _propertyCanRevert(name: StringName) : Boolean = throw NotImplementedError("_propertyCanRevert is not implemented for Object")
61+
open fun _propertyGetRevert(name: StringName): Any = throw NotImplementedError("_propertyGetRevert is not implemented for Object")
62+
open fun _set(name: StringName, value: Any) : Unit = throw NotImplementedError("_set is not implemented for Object")
63+
open fun _toString(): String = throw NotImplementedError("_toString is not implemented for Object")
64+
open fun _validateProperty(): Boolean = throw NotImplementedError("_validateProperty is not implemented for Object")
65+
66+
5867
open fun _notification(): GodotNotification = godotNotification {}
5968

6069
@Suppress("UNCHECKED_CAST")
@@ -78,7 +87,7 @@ abstract class KtObject : NativeWrapper {
7887

7988

8089
private fun removeScript(constructorIndex: Int) {
81-
createScriptInstance(ptr, objectID, TypeManager.engineTypesConstructors[constructorIndex])
90+
createScriptInstance(ptr, objectID, TypeManager.engineTypesConstructors[constructorIndex])
8291
}
8392

8493
protected external fun createNativeObject(classIndex: Int, scriptIndex: Int)

src/script/jvm_instance.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,17 @@ void JvmInstance::validate_property(PropertyInfo& p_property) const {
164164
}
165165

166166
String JvmInstance::to_string(bool* r_valid) {
167-
return ScriptInstance::to_string(r_valid);
167+
jni::Env env {jni::Jvm::current_env()};
168+
169+
if (KtFunction* function {kt_class->get_method(SNAME("_to_string"))}) {
170+
const int arg_count = 0;
171+
Variant ret;
172+
function->invoke(env, kt_object, nullptr, arg_count, ret);
173+
*r_valid = true;
174+
return ret.operator String();
175+
}
176+
*r_valid = false;
177+
return {};
168178
}
169179

170180
void JvmInstance::refcount_incremented() {

0 commit comments

Comments
 (0)