-
Notifications
You must be signed in to change notification settings - Fork 556
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 wren method handle from inside a bound foreign method body #1169
Comments
The VM is not currently reentrant, meaning a wrenCall can't happen inside a foreign binding. If you run a debug build you'll likely get an assertion about that? (always test in debug a bit for the assertions to be present atm) |
@ruby0x1 well that's rather disappointing, I was hoping there was a way to do what I'm trying. And yes of course, I'm running and testing on a debug build. But there are no asserts happening until it tries to run a method on the wrongly associated class (Game). The weird thing is that the Game handle that it tries to run it from is grabbed from the stackTop, and I inspected it's values a bit and it turns out the Item class value is somewhere in that stack, just not where I expect it to be. Whether or not there's a reason behind it I thought it was interesting to note. |
You can also split the static in 2 parts. A wren one that handle part of
the logic and one ore more private static foreign that handles the part
that needs to be done in C land.
|
@mhermier Somehow I missed your message, but indeed that is a solution. I will try that for now, thank you! |
Depending on your needs it's easy enough to fire up TWO entirely different Wren VMs... and one can call into the other - since it's not reentrancy at that point. I've used this strategy before. |
Let say that I have these two wren classes:
Somewhere in the main module I'm calling
Builder.create(Item)
.And let say that Builder.create is bound to this method:
The idea behind this is that the
Builder.create
function will construct the class that is passed in it's argument with a new() call, and return the new variable with some processing on the host side.The problem is that even tho I've verified the class handle to be of type 'Item metaclass', when calling
wrenCall
the following line of codevm->apiStack = NULL;
will remove the handle from the stack. SincewrenSetSlotHandle
internally callsvm->apiStack[slot] = value;
And will cause the app to crash as it's trying to call a function from a different class, in this case, the class that originally calledBuilder.create
which happens to be called 'Game'.Is this intended behaviour? And if so, then how can I achieve the functionality I need?
Note that if I change the create function to simple do this on wren side it works as expected (but without the host processing):
So it should in theory be possible to do this on the host side.
The text was updated successfully, but these errors were encountered: