Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Figure out if its possible to recursively add references to parent functions #9

@atomicptr

Description

@atomicptr

For example Godot has a class Called MeshInterface which inherits

GeometryInstance which inherits VisualInstance which.... Spatial....Node...Object etc.

when I have a MeshInstance object it should be possible to call the getNode function from Node directly on the mesh instance like this:

const tween = self.base.getNode(godot.Tween, godot.NodePath.fromString("Tween"));
tween.interpolateProperty(...);

this could be achieved by recursively adding all parent functions (unless it was already added, child functions should have priority...) to the current object (and then adding all functions of that parent as well...)

This is currently implemented in this file via the callUp function

godot-zig/src/main.zig

Lines 15 to 26 in 30ffc92

pub fn callUp(comptime T: type, obj: *T, comptime function_name: []const u8, args: anytype) !void {
if (!@hasDecl(T, "BaseClass")) {
@compileError("call can only be used with Godot objects");
}
if (!@hasDecl(T, function_name)) {
try callUp(T.BaseClass, obj.base, function_name, args);
return;
}
_ = try @call(.{}, @field(obj, function_name), args);
}

Obvious downside however that you can't do this with your current class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions