prime31 / zig-flecs

52 stars 9 forks source link

Iterator index is usize but i32 in flecs #27

Closed Srekel closed 2 years ago

Srekel commented 2 years ago
    index: usize = 0,

I'm using it like this:

    const md = flecs.c.ecs_term_w_size(it.iter, @sizeOf(fd.CIMesh), it.index);

More context:

fn onSetCIMesh(it: *flecs.Iterator(ObserverCallback)) void {
    var state2 = @ptrCast(*flecs.c.ecs_observer_t, @alignCast(@alignOf(flecs.c.ecs_observer_t), it.iter.ctx));
    var state = @ptrCast(*SystemState, @alignCast(@alignOf(SystemState), state2.*.ctx));
    _ = state;
    _ = state2;

    while (it.next()) |_| {
        const md = flecs.c.ecs_term_w_size(it.iter, @sizeOf(fd.CIMesh), it.index);
        _ = md;
    }
}

But this causes this error when using it:

expected type 'i32', found 'usize'

I can of course cast it, but I'm thinking it would be better to match the type that flecs uses?

prime31 commented 2 years ago

Probably best to just cast there. We need the usize for all array access which is why the index field is stored on the iterator.

Srekel commented 2 years ago

Ah right and in zig you can't use a signed int as an array index so then you would need casts there instead.