Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting a JS object to a void pointer as an opaque value and back #217

Open
anyc opened this issue Jan 13, 2025 · 0 comments
Open

Converting a JS object to a void pointer as an opaque value and back #217

anyc opened this issue Jan 13, 2025 · 0 comments

Comments

@anyc
Copy link

anyc commented Jan 13, 2025

Hello,

the C library I use offers the possibility to register an arbitrary void pointer as "userdata" with an opaque structure (lib_set_userdata()). If an event occurs, a generic callback function is called with the opaque structure as argument and I can retrieve the userdata from the structure using another function (lib_get_userdata()).

I currently fail to come up with a solution to pass an arbitrary JS object as void pointer and convert it back to the same object in the callback function. Is this somehow supported with Koffi? I guess, I could maintain my own list of userdata objects in a list and store the index in the void pointer and use the index later to convert it back to the object.

I saw that I could bind a callback function to an object with koffi.register() but in my case, the callback is generic and I need to reconstruct the JS object from a void pointer.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant