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

call.external to call with C function pointers #1836

Open
amorphobia opened this issue Dec 18, 2024 · 2 comments
Open

call.external to call with C function pointers #1836

amorphobia opened this issue Dec 18, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@amorphobia
Copy link

Thanks for creating the awesome language!

Is your feature request related to a problem? Please describe.
The external dll defines a struct:

typedef struct {
    // data ...
} data_t;
typedef struct {
    void (*initialize)(data_t *data);
    const char* (*get_version)(void);
    // other calls ...
} api_t;

__declspec(dllexport) api_t get_api() {
    static api_t api = {0};
    // initialize the function pointers in api_t struct
    return &api;
}

Is there a way to:

  • call function pointers of the external struct with either the address (offset) or the name?
  • initialize the data_t struct and pass its pointer to the external function?

Describe the solution you'd like

I'm OK to go with the addresses, since their offsets to the struct head are fixed. But it's even better to convert from struct pointer to a native dictionary.

For initializing a C struct from within arturo, I'm not sure it is able to do so now (not seen in the doc). I'd like to use a dictionary too, or a memory block is also OK.

Thanks again for the great work!

@amorphobia amorphobia added the enhancement New feature or request label Dec 18, 2024
Copy link

Thank you for submitting an issue! :)

@drkameleon
Copy link
Collaborator

drkameleon commented Dec 18, 2024

哪里哪里,谢谢你的鼓励!😉
(I'll continue in English because although I love Mandarin, (a) I'm not that advanced yet, (b) I want to answer... this year lol)

I'm afraid what you're asking about is something which I have no good answer to - yet!

Basically, our current call.external functionality could be considered the groundwork of what is to come, but I personally don't consider this neither sufficient nor complete by any means.

As I have written more than a couple of times, since we now have packages too, having access to external C libraries via Arturo would be a huuuge boost, so it will be one of my priorities, just after we finally manage to release the upcoming 0.9.84 version (not too long left; just ironing out some issues with the documentation mostly! :) ).

And then I'll do my best so that we have proper FFI.

(As a matter of fact, there have already been attempts - not 100% fruitful yet - but it makes me very hopeful I admit... @g3rwy for one almost-wrapped RayLib in pure Arturo and the results are promising! 😉 --> https://discord.com/channels/765519132186640445/829324913097048065/1212091507595681804)

Btw, you are absolutely welcome in our Discord server. It's a place where very interesting discussions take place usually and you can just ask away anything you want!

And again: Thanks a lot for your (very) kind words. That's what keeps me motivated! 🚀

Have a great day!

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

No branches or pull requests

2 participants