-
Notifications
You must be signed in to change notification settings - Fork 17
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
Binding a free function as a non-static member function #20
Comments
I'm not a contributor to this repository, but I'm fairly familiar with the codebase. Anyhow, here's my 2 cents. Firstly, why do you have a free function that takes a reference to MyData? Don't you think it'd be easier to simply put it inside the class? Also, since you are placing it outside of the class, it really should be static. Secondly, you are binding to a function that expects one parameter, but you provide none in the Wren version, so this won't work. Here's my advice, put the method inside the class and you can remove the self-reference parameter, then the code would do what you expect it to and it will be cleaner too, hope this helps! |
@ConorDamery Thanks for the reply! |
You can still do this. I'm going to assume the math library you are referring to is glm? For example:
|
I dont want to wrap the glm type just for scripting purposes. And the
second solution is exactly what I'm currently doing and trying to not do.
…On Tue, May 2, 2023, 3:06 AM ConorDamery ***@***.***> wrote:
You can still do this. I'm going to assume the math library you are
referring to is glm?
Anyway, there's nothing preventing you from wrapping glm into your own
vec3 class which mirrors the wren implementation.
And if you really don't want to do that, then you can still mirror the
wren implementation by providing a static method in your wren class which
does take a const vec3 reference (note the const reference is what really
matters as I mentioned before).
For example:
// wren
foreign class vec3 {
// constructor, etc...
foreign static length(v)
}
// cpp
.bindMethod<decltype(glm::length<glm::vec3>), &glm::length<glm::vec3>>(true, "length(_)")
—
Reply to this email directly, view it on GitHub
<#20 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMZGPZRQTRK4FDTUVDG7R3TXEBCIZANCNFSM6AAAAAATPQQ5QM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Alright fair enough, well my only other approach is to try hacking it using wren semi-directly, which should work in theory (the code is not tested!).
|
I'm trying to bind a free function, as a non-static member function of a foreign class.
Here is my Wren code:
And here is my C++ code (module names are handled correctly):
When I run it, I get:
And then it segfaults.
Using a static function (binding
twiceValue
as static and passing instance as its first parameter) or a member function works fine.The text was updated successfully, but these errors were encountered: