Shop OBEX P1 Docs P2 Docs Learn Events
pointer to OBJ ? — Parallax Forums

pointer to OBJ ?

janbjanb Posts: 74
edited 2007-01-21 22:33 in Propeller 1
Hi,
I know spin does not support pointers, so I'm asking if there is perhaps some tricks I could play to
immitated them.
The· SubEventF10· (attached) is a typical data block container with 3 memeber variables:
·var
·· byte myKey
·· byte len
·· byte data[noparse][[/noparse]mxLen]

and bunch of get/set methods:
.............
PUB clear
PUB addD(b) ' add one byte to Data
PUB getD(i) ' get one byte from Data
PUB size
PUB new(xkey)
PUB key
...........

I'd like to use array of this OBJ and manipulate sametimes only on one item. So the main program (which later on will be also a OBJ of higher level) would look like:
OBJ
·· eve[noparse][[/noparse]3]: "SubEventF10"
PUB· main |k
·· eve1:=@eve[noparse][[/noparse]1]
·· eve1.clear
·· eve1.addD(33)

Of course·it does not compile. I do not know how to define 'eve1' - the pointer to an element of type SubEventF10·

Is there any trick you could recommend to acomplish it in spin?
Thanks
Jan

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-21 22:33
    You can't access the data elements of an object directly in Spin. What you could do is to have a method in "eve" that returns the address of its work area, then manipulate that using BYTE/WORD/LONG. The operating system that I wrote uses something like this for its work area that it allocates dynamically at the end of Hub memory. All of the work area variables are defined as constant offsets from a pointer that's stored at a fixed location at the end of memory. The named constants are indeed accessible symbolically from other objects. Download the OS and have a look at one of the objects like "OS_dspText".
Sign In or Register to comment.