Skip to content

Initialization of libgodot as a gdextension DLL with libgodot symbols for Zig #2

@fire

Description

@fire

Hello, I'm trying to use libgodot but for zig following the c++ sample.

The primary use for this is to for Zig to call the GodotInstance class and start, iterate and shutdown. Also, the gdextension should be possible to be coded normally in zig.

This is causing some confusion and difficulties for me. I am lost understand the flow of the initialization compared with the standard gdextension flow.

Any help or guidance on how to achieve this would be greatly appreciated.

References

https://github.com/godot-zig/godot-zig

We assume that zig is using the libgodot_project's .h and .json.

const std = @import("std");
const Godot = @import("api/Godot.zig");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    const allocator = gpa.allocator();
    defer _ = gpa.deinit();

    const args = try std.process.argsAlloc(allocator);
    defer std.process.argsFree(allocator, args);

    var argvs = std.ArrayList([]const u8).init(allocator);
    defer argvs.deinit();

    for (args) |arg| {
        try argvs.append(arg);
    }

    // Append additional arguments
    try argvs.appendSlice(&[_][]const u8{
        "--path",
        "../../project/",
    });

    std.debug.print("There are {d} args:\n", .{argvs.items.len});
    for(argvs.items) |arg| {
        std.debug.print("  {s}\n", .{arg});
    }

    var instance = Godot.GodotInstance.newGodotInstance(); // TODO: newGodotInstance somehow instantiates and or gets the godot extension pointer from c header?
    
    if (!instance.start()) {
        return;
    }
    
    while (!instance.iteration()) {
        continue;
    }
    
    instance.shutdown();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions