Comments (3)
Currently your script has on_create
defined as static on_create(object)
. This means that script->receiver
must be the Test
class itself and the signature passed to wrenMakeCallHandle
(which returns the value used for script->on_create
) should be "on_create(_)"
(single underscore for single parameter).
Your engine ensures 3 slots, extra slots should just be ignored when calling wrenCall
so slot 0 is the receiver and slot 1 is the value for object (slot 2 is extra so it would just get ignored).
If you want to pass just the foreign object to the function parameter, you could put the object class in slot 2 and create the foreign function in slot 1 instead using wrenSetSlotNewForeign
(might be able to get away with putting the object class in slot 1 then replacing it with the foreign object to the same slot but you should test that first)
if you want both the object class as well as the foreign object passed to on_create
, you'll need to create a method with signature: "on_create(_,_)"
(2 underscores for 2 parameters, also you'd use this signature for wrenMakeCallHandle
instead). This allows the value in slot 2 to be used as the second parameter.
I'm not completely certain I fully understand the situation so feel free to clarify if I misunderstood the issue.
from wren.
If you want to pass just the foreign object to the function parameter, you could put the object class in slot 2 and create the foreign function in slot 1 instead using wrenSetSlotNewForeign (might be able to get away with putting the object class in slot 1 then replacing it with the foreign object to the same slot but you should test that first)
@CrazyInfin8 oooh that worked just fine! Thank you!
What if I want to remove the static
from the functions and do something like Lua's metatables for the foreign object where I can implement new functionality in runtime?
So instead of doing like I did with the static methods, I have something like this:
class Test {
construct new() {}
on_create() {
System.print(this.name) // this = the foreign object
System.print("Hello from on_create")
}
on_update(dt) {
}
on_destroy() {
}
}
from wren.
to remove static
from the functions, you'd need an instance to call them first. You can create an instance using one of the following methods
- You could
wrenInterpret
some script that creates that instance usingTest.new()
, store the resulting value in a top-level variable, then usewrenGetVariable
to get the instance value to use in C. - Alternatively you could use
Test
as the receiver (slot 0),new()
as the signature forwrenMakeCallHandle
,wrenCall
that handle, and (assuming no errors) slot 0 should contain a brand new instance of the classTest
(return values of wren functions are placed in slot 0).
After you've done one of these, you can proceed to use that instance as the new receiver (instead of using the class itself) when calling on_create
, on_update
, on_destroy
.
from wren.
Related Issues (20)
- [Feature] Pipe Operator for Function Calls HOT 53
- [RFC] Object.responds(_) method HOT 10
- [RFC] Add routines for degrees/radians conversions HOT 21
- [RFC] Adding a `Tuple` with language support HOT 11
- [RFC] Adding `const` versions of `Object`s. HOT 9
- Class reflection for embedding HOT 2
- [RFC] `veery` lang transpiler to `wren` lang HOT 3
- [RFC] Object method message passing syntax HOT 28
- [RFC] Add `static Object.typeOf(_)` (and deprecate `Object.type` ?) HOT 9
- How can i stop wren script running? HOT 3
- Calling wren method handle from inside a bound foreign method body HOT 5
- Whitespace bugs? HOT 4
- Serialize (suspended) fibers or serialize the vm HOT 4
- wren_debug.c should use vm->config.writeFn instead of printf HOT 1
- Should we document this aspect of for loop control variable behavior?
- is Wren dead? HOT 2
- Where causes code to be called twice HOT 3
- How to return other foreign class obj from a foreign class ? HOT 7
- wrenCall -> foreign call causes memory corruption HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wren.