Shop OBEX P1 Docs P2 Docs Learn Events
Chain object in spin? — Parallax Forums

Chain object in spin?

jmspaggijmspaggi Posts: 629
edited 2010-10-06 06:02 in Propeller 1
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
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

  • Heater.Heater. Posts: 21,230
    edited 2010-10-06 05:42
    jmspaggi

    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.....
  • jmspaggijmspaggi Posts: 629
    edited 2010-10-06 05:51
    So catch 22 ;) RAM... Features... RAM... ;)

    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
  • Heater.Heater. Posts: 21,230
    edited 2010-10-06 05:56
    jmspaggi
    ...if I put my variable in the DAT section, it will be shared between all the instances of my object, correct?

    That is correct.

    A Spin method cannot call any PASM code. It can only start PASM code in a new COG.
  • jmspaggijmspaggi Posts: 629
    edited 2010-10-06 06:02
    Ok, thanks. I only need 1 word and 2 long per instances. So I will try to see what I can do with the DAT section.

    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
Sign In or Register to comment.