Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fire opened this issue Apr 16, 2024 · 0 comments

Comments

@fire
Copy link

fire commented Apr 16, 2024

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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant