Lib with variable arguments of variable types?

Everything else that doesn't fall into one of the other PB categories.
Justin
Addict
Addict
Posts: 956
Joined: Sat Apr 26, 2003 2:49 pm

Lib with variable arguments of variable types?

Post by Justin »

It's possible to do a lib with functions that accept variable args of variable type?, something like CallFunction()

in the .desc file the arguments are of fixed type so it seems not possible?
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Try to use 'ANY' as a type in the desc file, it might work?
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Lib with variable arguments of variable types?

Post by traumatic »

If you're using Long as parameter type you can also pass string from
PureBasic if this helps (don't know if this is a feature though...).

Regarding varargs:
You'll need to make a different functions, 'real' varargs are not
supported.

Code: Select all

   2. Examples of variable parameters
      - - - - - - - - - - - - - - - -

   2.1 One, two or tree parameters
  
     CustomBox, String, [Long], [Long], (Title$ [, Flags [, Hidden]]) - My Custom box
     Long

     Now, you have to create 3 PB functions, named like this:
     PB_CustomBox (char *String)
     PB_CustomBox2(char *String, Long)
     PB_CustomBox3(char *String, Long, Long)
Good programmers don't comment their code. It was hard to write, should be hard to read.
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Using 'Any', as Pupil said, is the right way. Here is for example the definition of CallFunction in the .desc:

Code: Select all

CallFunction, Long, String, [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], [Any], (#Library, FunctionName$, [Arg1, [Arg2, ...]]) - Call a function using its name.
Long
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

And you can use various labels in the same function, but you'll need a way to know how many args have been pushed.
El_Choni
Justin
Addict
Addict
Posts: 956
Joined: Sat Apr 26, 2003 2:49 pm

Post by Justin »

thanks, i think i'll pass arguments with its type through an array. it seems there is no way to know wich type of argument has been passed from within the lib function
Post Reply