Passing an Object
EB
Posts: 8
Is is possible to pass an object as an argument to a function? I can pass a pointer to the object, but it complains on the other end of about syntax. Is there some way to dereference the pointer on the other end so that it's members can be accessed?
Comments
There are a few tricks which can allow this functionality to be achieved, or something close to it. Those who have worked on such things will hopefully pass-by and point to relevant previous posts, or dive in with a forum search. It's quite complicated though, especially if new to the Propeller.
it's a propeller NOT a PC !
Do you really think within an application that has to fit into 32kB of RAM needs such complicated things?
best regards
Stefan
It's not actually that complicated in most cases, get the address of method to call from a variable rather than load it as a constant determined at compile time, however the way Spin bytecode makes method and cross-object calls makes it more difficult.
so can you post a code-snippet that shows how it works and how it is saving RAM ?
best regards
Stefan
Without that, it needs a long Case statement to call a selected method.
A hack to the above first example to allow method pointers if not officially supported would be to overwrite the operand of the JSR #Method with the desired address at run-time, however Spin bytecode isn't quite so straight forward as that.
This is possible but not all that easy. I've been working on it for awhile now (although not much for the last month or two, when I get some time I'll do some more). Here is the thread you want http://forums.parallax.com/showthread.php?p=701497.
The latest version isn't really quite ready for any real use yet but it is getting close. The demo shows passing of objects and things. It would probably be possible to pass functions as well but I haven't tried it. If you bug me enough it may even help me get a new version out sooner .