Shop OBEX P1 Docs P2 Docs Learn Events
Pointers to functions — Parallax Forums

Pointers to functions

darcodarco Posts: 86
edited 2008-02-12 05:37 in Propeller 1
I'd like to be able to pass a pointer to a function to another function, which can then call that function a number of times with different parameters. I'm very comfortable with pointers in C, but the syntax of this language is really making my head.......spin.

Is it possible to execute a given function if you have a pointer to it? If so, what is the syntax to do this in Spin?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

darco
www.deepdarc.com/
[url=mailto:xmpp:darco@deepdarc.com]xmpp:darco@deepdarc.com[/url]

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-12 02:41
    You might give my callback object a try. Be sure to read all the caveats. It's not as tidy a solution as one might hope for, but it works.

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-12 05:14
    darco,
    To answer your question more directly: There are no pointers to functions in Spin and you can't execute a function given a pointer. That said, it is possible to "fool" the interpreter as Phil has done, to locate the internal tables used to point to the actual interpretive code for a function and to "patch" them with the address of a different block of interpretive code so that the new piece of code is executed in place of the compiled one.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-02-12 05:37
    If you want a slightly more structured way to do it have a look at DOL here http://forums.parallax.com/showthread.php?p=701497
Sign In or Register to comment.