Shop OBEX P1 Docs P2 Docs Learn Events
Does an Object have an address that can be used in SPIN? — Parallax Forums

Does an Object have an address that can be used in SPIN?

eldonb46eldonb46 Posts: 70
edited 2012-07-10 00:02 in General Discussion
Is there a way to access an Object via Numeric?

In my case I have several Display Objects: Parallel LCD, I2C LCD, VGA, etc, etc
OBJ
  DSPA : "jm_lcd....
  DSPC : "BiZ_lcd....
  DSPC ; "VGA"
  etc, etc

What I would like to do is something like:
PRI
  DSP[0] := DSPA
  DSP[1] := DSPB
  etc, etc

Then, for example:
repeat i from 0 to 4
  DSP[i].Clear
  DSP[i].Dec(Value)


Of course, this becomes more interesting, and useful, for a more complex example.

So, Is the address or pointer available for an Objects (or its Methods)?

Currently I am writing SPIN code with large Case statements for each of the "like" methods contained within each Display Object.

It would be nice it if there is an easier way :smile:

Thanks
Eldon

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-08 20:08
    No. Spin does not provide a mechanism for dynamic object or method references. That's not to say that you can't game the system, but it's not part of the language.

    -Phil
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-07-09 05:16
    As Phil implied, you could "game the system". Add an additional dummy object to the list, and then use it's entry in the method table to access the other objects. You would have to copy the object address and VAR size to the dummy object entry before accessing the desired object. You also need to ensure that all the objects contain the same method definitions in the same order. The methods in the other objects don't necessarily have to have the same names, but they do need to have the same number of calling parameters, and be in the same order.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-07-09 09:30
    Dave Hein wrote:
    You also need to ensure that all the objects contain the same method definitions in the same order.
    Only the public methods need to be in the same order, even if interspersed differently with private methods, since public and private methods are grouped separately in the method dispatch table.

    -Phil
  • eldonb46eldonb46 Posts: 70
    edited 2012-07-09 20:49
    Phil - thanks,

    I do not expect I will "game the system" in SPIN, that is beyond my pay grade. :frown:

    But, . . . does the new "C/C++" IDE provide Standard I/O File Descriptor (fd) or logical units, that would provide desired functionality?

    Thanks,
    Eldon
  • Heater.Heater. Posts: 21,230
    edited 2012-07-10 00:02
    Sure. In C++ you can set up an array of objects like the idea in the first post. You can do it in C with structs and function pointers. And as you say there are those file handles.
Sign In or Register to comment.