Zig NEWS

Discussion on: Function Tables

Collapse
lhp profile image
Leon Henrik Plickat

You can put all the functions in a list, index into the list and call the function.

You should be able to put the functions in a struct and index into @typeInfo(impl).Struct.decls[i]. Also you could use a comptime [enum tag <-> function pointer] map, or compare @tagName against decls[i].name.

Although I personally can't think of any case right now where I'd not just use an enum plus a switch. It's a lot more straight-forward.

Maybe we'll have anonymous functions functions in the future. Perhaps then using a union(enum) of functions could be interesting, if only to avoid having to keep the enum, the action implementation and the matching code in sync.