Chain object in spin?
jmspaggi
Posts: 629
Hi all,
Let's imagine I have an object X with a method Action.
I want the object X to be able to receive another object X in parameters.
Then when I will call the Action method from my first object, I want it to call the Action method from the received object, if any.
If I define in object X
I have a circular reference. And I understand that, I have even expected that
Now, if I give the next object addr as a parameter to my current object, I can get the address, but how can my current object know that it's an X object?
Can I do something like ((X)addr).method?
Thanks,
JM
Let's imagine I have an object X with a method Action.
I want the object X to be able to receive another object X in parameters.
Then when I will call the Action method from my first object, I want it to call the Action method from the received object, if any.
If I define in object X
OBJ nextX : "X"
I have a circular reference. And I understand that, I have even expected that
Now, if I give the next object addr as a parameter to my current object, I can get the address, but how can my current object know that it's an X object?
Can I do something like ((X)addr).method?
Thanks,
JM
Comments
You cannot get the address of an object or any methods in Spin. So you cannot pass such addresses as parameters to other methods.
At least not in any "normal" Spin/PASM programming.
Spin is not like C where you can pass functions as parameters and despite the fact it has "objects" and the "object.method" notation it is not in anyway object oriented in the sense of C++ and such.
If you really, really, have to do such things to program a solution to your problem you are going to need C or C++ on the Prop via the ICC compiler, Catalina or Zog. But then you are going to find there is not enough RAM space.....
To do that, I will have used the Java JVM from Jazzed and Peter, but all my code is in Spin
So another option.
Can I share one variable between all the instances of my object and access this variable in the Spin code?
If I understand correctly the way it works, if I put my variable in the DAT section, it will be shared between all the instances of my object, correct?
There, I can store an array which will contain the address of my objects variables used in the Action method.
So when one X object call the Action method, it can look at it's own values, but also at other X objects variables values through the DAT section, and process them the same way?
Is that something which can work?
On the same side, is it possible for a Spin method to call a PASM method? Or only a PASM cog can do that?
Thanks,
JM
That is correct.
A Spin method cannot call any PASM code. It can only start PASM code in a new COG.
I'm working on a Timer object. It's already working pretty well, but would like to have as many instances as Timers as I want without having to "Trick" them all...
I will post the object on Obex by the end of the week. It's mainly a migration from the Javelin code
JM