Skip to content

exportFn fails during semantic analysis #7

Closed
@galli-miro

Description

@galli-miro

I've tried to build a simple shared module using the exportFn in a comptime block. Using zig version v0.11.0-dev.1638+7199d7c77 it fails with the following error:

/home/galli/repos/git.sr.ht/~hubidubi/river-lua/zig/lib/ziglua/src/ziglua-5.4/lib.zig:2021:13: error: TODO implement exporting arbitrary Value objects
    @export(declaration, .{ .name = "luaopen_" ++ name, .linkage = .Strong });

Since there is a TODO, I'm assuming this will be fixed at some point. But git blame tells me this TODO has been there for over 2 years, so who knows when that will happen.

build.zig:

const std = @import("std");
const ziglua = @import("lib/ziglua/build.zig");

pub fn build(b: *std.Build) void {
    // Standard release options allow the person running `zig build` to select
    // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const lib = b.addSharedLibrary(.{
        .name = "test",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });
    lib.addModule("ziglua", ziglua.compileAndCreateModule(b, lib, .{ .shared = true }));
    lib.install();
}

main.zig:

const std = @import("std");
const ziglua = @import("ziglua");

usingnamespace ziglua;

fn hello(lua: *ziglua.Lua) i32 {
    _ = lua;
    std.debug.print("hello world\n", .{});
    return 1;
}

fn module(lua: *ziglua.Lua) i32 {
    var fns = [_]ziglua.FnReg{ .{ .name = "hello", .func = ziglua.wrap(hello) }, .{ .name = "", .func = null } };
    lua.newLib(fns[0..]);
    return 1;
}

comptime {
    ziglua.exportFn("hello", module);
}

My current fix is to do the exporting and wrapping by hand, but maybe I'm missing something:

export fn luaopen_module(L: *ziglua.LuaState) callconv(.C) c_int {
    var fns = [_]ziglua.FnReg{ .{ .name = "hello", .func = ziglua.wrap(hello) }, .{ .name = "", .func = null } };

    var lua = ziglua.Lua{ .state = L };
    lua.newLib(fns[0..]);

    return 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions