-
Notifications
You must be signed in to change notification settings - Fork 4
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
Can it wrap native class (methods)? #2
Comments
Yes
They are automatic (and require D creation function for classes but not for structs). And looks simply like
They are destroyed when the reference count is decreased to 0. The reference count is decreased when the C# object is finalized.
Yes. It is a bit buggy. For example, extern(C) function shouldn't return ref-counted structs/objects. Also the class C# should be inherited from MirPtr or MirSlimPtr. I will rework it at the end of this week and add it to the CI. |
Ok, thanks. I'll try to mess a bit with existing code, but having an example for reference certainly will be helpful. |
@Superbelko Do you need an example with inheritance support or plain pointers? |
As you've mentioned earlier, simply deriving from MirWrapper seems to make factory function unnecessary(or I could be totally wrong since in such basic example there is no internal state that could mess up with ABI), however I haven't figured out myself how to call methods on wrapper implementation. So it would be awesome if you provided some demo case with native classes, including methods and data access. |
I've seen this library was mentioned somewhere on D forums in a fashion like it can be used to wrap native class.
So my questions:
Is it possible to wrap unmanaged class?
And what about allocations?
How to destroy objects?
Is there a better way to wrap this code?
My use case is basically wrap some D code (mix of classes/structs/free functions) to use in C#, possibly extend with inheritance.
Code:
I've slapped some basic test code, on D side there is a simple C++ class with 3 virtual and 1 final methods and no members, there is also factory function to create this one, this class is then loaded on .NET side and called directly using delegates.
And the followind C# code, it kind of works and I can wrap it further with some scripting so it can be inherited
The text was updated successfully, but these errors were encountered: