manifold.wasm works only with JavaScript #242
Replies: 19 comments
-
Agreed, I believe the only purpose of WASM is to create JS bindings. What other languages are you interested in binding to? These JS and Python bindings are due to community contributions, for which I am hugely thankful as that part I'm not familiar with. If you'd like to contribute more here that would be fantastic! |
Beta Was this translation helpful? Give feedback.
-
Definitely not. For example there's a server "OS" under development that is using WASM as it's plugin architecture. You can use WASM files in many languages... list from the Byte Code Alliance README: |
Beta Was this translation helpful? Give feedback.
-
I guess you can create a C API and use it for all other languages? Although I'm not sure if we would want to maintain such an API, there are already the official C++ API, Python and JS API that we need to maintain. |
Beta Was this translation helpful? Give feedback.
-
The problem with binding generator is that the general binding is not very ergonomic for others to use, so if we use it to generate the js and python binding, we still need significant effort to make an ergonomic interface. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I would love to see what that looks like; do you want to start a PR @briansturgill? Perhaps there's room for a generic low-level API with more ergonomic, language-specific niceties on top. Being not much of a C-developer, what in our case would be the big difference between our C++ API and C? Is it mostly avoiding the use of I don't want to commit to this route yet; @pca006132's points regarding maintainability are valid, but I would also like to be convinced. |
Beta Was this translation helpful? Give feedback.
-
My main concern is regarding the use of smart pointers. Our current C++ API is functional, so users have to be responsible for dropping a lot of intermediate states if they want to discard them. I guess maybe we can provide a C API that is not functional by default, and users have to clone the objects explicitly? (just do the operation and drop the old result internally) Not sure if that would be more ergonomic. |
Beta Was this translation helpful? Give feedback.
-
The alternate WASM binding would be similar to what it would look like... I can show that to you when it's done (though I don't think you want that to be a pull request). Most importantly, the C API should be easy to use... you've used OpenSCAD, see it's cheat sheet. Here's the Python wrapper. JSCAD's ergonomic API is a bit painful, so I don't think I'll hold that one up as an example. |
Beta Was this translation helpful? Give feedback.
-
What's the story with blobs? C supports objects with methods. The rest seems reasonable, though I don't know how much code it'll take. I like to think our C++ API is pretty easy to use, and it's based strongly on OpenSCAD's already. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what you mean by C supports objects with methods. C doesn't have classes. Gcc allowed some C++ features to be used from C, but even then it I don't think that was allowed. It won't take that much code. Basically you decide on what parts of the API you want to expose and make a C wrapper that talks to your fancy C++. Your API really isn't that easy to use... consider the case of creating a Manifold from points. I never did manage to get a proper export of manifolds to glb to work (in Python). Had to insert code into your run_all.py to get output. (When I called what seemed like the exact same code in a "save" function, I kept getting complaints about skipping an empty mesh.) I think the use of C++ operator overloads will cause most users confusion.I know why ^ is intersect, but really, you expect most OpenSCAD users to understand that? |
Beta Was this translation helpful? Give feedback.
-
Oh, perhaps it was my use of the word "blob" that is the problem. I just mean you'll return a void *. It will be untyped from a C perspective. |
Beta Was this translation helpful? Give feedback.
-
You can just declare it by
No need to use void* in this case... Everything is type safe. |
Beta Was this translation helpful? Give feedback.
-
It might well work, but it's not proper "C" and is not guarenteed to work. The people calling the C API will not be parsing your Manifold headers. They may not be parsing any headers at all. (For an example, consider ctypes from Python .) |
Beta Was this translation helpful? Give feedback.
-
How is this not proper C? This is very typical for C libraries to forward declare a struct and hide the implementation from the users. User code will not know the size of the object and can only work with the pointer of the object, just like void* but is much safer. For FFI, a pointer is just a pointer, nothing is changed. I know the intent of the C API is for FFI, but it doesn't mean that we need to throw away the types. And yes, I did work with C FFI before. |
Beta Was this translation helpful? Give feedback.
-
And just how did you pass a C struct definition to something like Python ctypes, or C#, which access a C dll like this: You use void * because the C spec says that is what void * is for, a pointer which is untyped.
The point here is that Manifold object is a BLOB, not something the host language should be messing with, except to pass it back. |
Beta Was this translation helpful? Give feedback.
-
Can you please have a look at this:
From C# and Python point of view, there is no different. But if someone wants to use a language with native C FFI support, such as Rust or Zig, having a type safe interface will be better. |
Beta Was this translation helpful? Give feedback.
-
I'm confused about what you want me to look at. |
Beta Was this translation helpful? Give feedback.
-
Thank you, I've learned a lot from this discussion, particularly how little I know about C. @briansturgill it sounds like you have ideas for how to improve things, but it's a bit hard to tell what magnitude of changes you're talking about. Let's do further discussion in the context of a PR, as contributions are always welcome. |
Beta Was this translation helpful? Give feedback.
-
Sorry I don't want to waste more time on this pointless debate. Type information exists outside the specific DLL. You are fine to send a PR for your C API, and then I will review it. |
Beta Was this translation helpful? Give feedback.
-
The value_object and class embind directives work only for JavaScript.
See embind docs for details.
I know of no way to get this to work with other languages.
It also seems to require unknown exports by the client language, so using those directives effectively makes that
binding JavaScript only.
NOTE: the use of those directives makes it work very easily in JS, I'm arguing for a second binding, not getting rid of the current one.
I'm looking into making my own binding for what I need.
Along the same lines I notice you are rolling your own Python binding.
I really think you would be better off making a "C" binding and then using a tool like SWIG to generate bindings.
This would allow you to get to many other languages automatically.
This is one of the major drawbacks with using C++ for this kind of project. C++ doesn't play well with other languages.
Having a dual C interface is probably the easiest to maintain solution.
Oh, SWIG supposedly has support for C++, but you use very advanced C++ and I know a large number of projects use the C binding approach instead. Certainly the "C" bind approach is easier to use in SWIG.
Beta Was this translation helpful? Give feedback.
All reactions