-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Calling C code from JavaScript involving Structs #3083
Comments
In WebIDL, you can use For efficiency, though, it is much better for your APIs to hand off pointers to objects. |
Thank you for your quick response. By now, I managed to convert above example using Embind as follows:
That works just as expected. When trying WebIDL, I was not able to export a function which is not a method belonging to a class. It seems that you always have to define an interface, at least in the examples I came across. Is that correct? |
Yes, WebIDL currently exports only classes and structs, I don't think
On Tue, Dec 16, 2014 at 11:03 PM, Philipp Burckhardt <
|
Thanks for the clarification! |
First let me say, this is an amazing project!
Now my question:
I am in the process of transpiling a C library to JS which should then be used as a node.js module. While I managed to export functions accepting or returning standard types such as floats or doubles, the documentation is not clear on how to properly convert functions accepting or returning custom C structs (the Embind and WebIDL facilities seem to be tailored only at C++ code).
Consider the following artificial example:
Ideally, I would like to end up with a constructor function than can create 3d vectors and a length function to calculate their length. This seems to be a quite common task when porting C code, but browsing the Internet I couldn't find a proper explanation of how to proceed? I would greatly appreciate if someone could tell me whether and if so how one can convert such C code to JavaScript. I found a discussion on the Google group (Link) suggesting that it is possible, but was not able to reproduce the necessary steps, so a worked example would be of much help.
Best,
Philipp
The text was updated successfully, but these errors were encountered: