Shop OBEX P1 Docs P2 Docs Learn Events
Passing parameters to a method — Parallax Forums

Passing parameters to a method

Gerry KeelyGerry Keely Posts: 75
edited 2009-08-07 08:54 in Propeller 1
Hi

Just wondering if it is possible to pass a·varying number of parameters to a method.
What I want to do is to send data to the serial port which would consist of a command(defined as a CON) plus byte variables.However the no. of variables passed to the method could be different each time.Is this possible in spin?

Regards

Gerry
·

Comments

  • ericballericball Posts: 774
    edited 2009-08-06 13:13
    No. SPIN doesn't have the concept of variable parameters. What you could do is define a set of functions for each of the commands, then have those functions invoke a single function which has the maximum number of parameters.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • Nick MuellerNick Mueller Posts: 815
    edited 2009-08-06 13:53
    You can always pass a pointer to the variables, or a pointer to an array of pointers.

    Nick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Never use force, just go for a bigger hammer!

    The DIY Digital-Readout for mills, lathes etc.:
    YADRO
  • SamMishalSamMishal Posts: 468
    edited 2009-08-07 08:54
    The best way to accomplish this is to have all your parameters put into a contiguous set of variables
    or an array.

    Then pass to the method two parameters. The first one is the number of parameters and the second
    is the address of the first variable in the set of contiguous variable or the address of the first element
    of the array.

    Your method can then use Long[noparse][[/noparse]address][noparse][[/noparse]k] or byte[noparse][[/noparse]address][noparse][[/noparse]k] or word[noparse][[/noparse]address][noparse][[/noparse]k] to access the
    variables needed. If the contiguous set is not of the same type then you can calculate the offsets required.
    If the variables are not possible to put into a contiguous set or an array then you can use an array of pointers
    where each element in the array holds the address of each variable in the set of the parameters needed.

    ·
    Samuel
    ·




    Post Edited (SamMishal) : 8/7/2009 9:01:54 AM GMT
Sign In or Register to comment.