Wasm callback into struct fn, and accessing struct values

I made some good progress this week :slight_smile: but now tripped over something basic again. I just added a javascript call-back into my zig/wasm upon mouse click. I implemented a listener pattern in Zig, such that I store a bunch of listeners based on them implementing the following function:

pub const Click = fn (x: f32, y: f32) void;

and registering interest:

pub fn addClickListener(listener: Click) void {...}

I ‘register’ my click listener within a fn within a struct, passing in the reference to the click fn, also implemented within that same struct. But then I realised that I cant access the struct member values from within that implemented fn :frowning: (and it seems not possible to use anon fn’s and state capture)

I found a trick using fieldParentPtrbut in this case I don’t have a ‘self’ reference

pub fn clicked(x: f32, y: f32) void {
         const parent = @fieldParentPtr(StarRenderer, "scene", self); //no self

Which makes me think that a fn defined within a struct in this way (i.e. not taking a self reference) is basically just a name-spaced static fn?

I thought I had found another work-around, by storing the value I need in a var within the struct, but from what I am seeing, it looks like such ‘struct vars’ are also static name-spaced vars?

I cant find documentation on this, so feeling a bit lost on how to progress. Is there any way that I can access the parent struct state from within the click fn implementation?

Zig 0.8.1