It seems I was wrong above, they are actually intended to be used to
retrieve rather than set arguments for functions.
This effectively means that you can declare a function that will take a variable amount of parameters.
I wrote a quick example for you; as you can see we must be careful to let the function know how the arguments it will receive do look. Failing to follow the correct format will throw exceptions or crash your program.
pFunc = get ptr to function("Func")
call function ptr pFunc, "ifsd", 1, 2.3, "Four", 0x5
wait key
end
` Function capable of accepting a variable number of arguments.
` We still need to keep track of how many and what kind of arguments it will
` receive so that will have to be provided to the function as well.
` We'll use a fugly system where the first argument must be a string; each
` character in this string corresponds to the argument type at the same offset as
` the character is in the string.
function Func(format as string)
hArgs = open arglist()
` Even if we CAN read this directly as seen above, we still have to skip over it in the argument list
format = fast upper$(arglist string$(hArgs))
strlen = fast len(format)
if strlen < 1
print "Func() called with zero trailing arguments.";
else
print "Func() called with "; strlen; " trailing argument(s):"
endif
` List the received arguments
for c = 1 to strlen
printc space$(4) + padleft$(str$(c), "0", fast len(str$(strlen))) + ": "
select mid ascii(format, c)
case 73: ` 'I'
print "integer("; arglist integer(hArgs); ")"
endcase
case 66: ` 'B'
print "byte(#"; hex$(arglist byte(hArgs)); ")"
endcase
case 87: ` 'W'
print "word(#"; hex$(arglist word(hArgs)); ")"
endcase
case 68: ` 'D'
print "dword(#"; hex$(arglist dword(hArgs)); ")"
endcase
case 70: ` 'F'
print "float("; arglist float(hArgs); ")"
endcase
case 83: ` 'S'
print "string('"; arglist string$(hArgs); "')"
endcase
case default:
print "UNKNOWN FORMAT IDENTIFIER ('"; mid$(format, c); "'); this will probably mess up the arglist reading!"
endcase
endselect
next c
print "-------------------------------"
endfunction
"Why do programmers get Halloween and Christmas mixed up?" Because Oct(31) = Dec(25)