#error: cannot dereference non-pointer type '@TypeOf(.enum_literal)'

1 messages · Page 1 of 1 (latest)

crimson plover
#
const std = @import("std");
const dynlib = std.DynLib;

const player = @import("./../player/player.zig");

pub fn start() !*Server {
    var lib = try dynlib.open("./test.dll");
    var start_server = lib.lookup(*const fn () callconv(.C) *anyopaque, "start_server").?;

    var s: Server = {
        .handle.* = start_server();
    };

    return &s;
}

pub const Server = struct {
    handle: *anyopaque,

    var lib = dynlib.open("./test.dll").?;
    var accept_player = lib.lookup(*const fn (*anyopaque) *anyopaque, "accept_user").?;

    pub fn accept() player.Player {}
};```
error: ```rust
src\server\server.zig:11:16: error: cannot dereference non-pointer type '@TypeOf(.enum_literal)'
        .handle.* = start_server();
        ~~~~~~~^~
referenced by:
    main: src\main.zig:7:23
    callMain: C:\zig\lib\std\start.zig:609:32
    remaining reference traces hidden; use '-freference-trace' to see all reference traces```
shrewd furnace
#

The initialization syntax for var s is wrong. You want one of these:

var s: Server = .{ // <-- leading dot as a placeholder for type
    // ...
};
// or
var s = Server{
    // ...
};
#

Without either a leading type or . in front of the curly braces, the exprission { ... } is a block. With a dot or type, it is a struct/union literal initialization, which is what you want.