Skip to content

storing an interface in a generic type, like ArrayList? #3

@emperor-limitless

Description

@emperor-limitless

so I was planning to use this for a stack based state machine thing, which requires me to have an ArrrayList or the equivilant, however, if I do

const std = @import("std");
const interface = @import("interface").Interface;

const State = interface(.{
    .onEnter = fn(anytype),
    // ...
});

const StateManager = struct {
    stack: ArrayList(anytype), // error.
}

so I'm wondering how can I store instances of struct? Note, it's not limited to one implementation, I could have a MenuState, A Gameplay state, etc, so having it store anything that implements the State interface is necessary

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions