Default parameters for PB library functions

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Default parameters for PB library functions

Post by Danilo »

Example .desc:

Code: Select all

MsgBox, Long=0, String="", String="", Long=0, (WindowHandle, Body$, Title$, Flags) - Display an MessageBox
Long | DebuggerCheck | Unicode

TheFunction, Long, Long, String="hello", (value1, value2, string = "hello") - do something
String | DebuggerCheck | Unicode
Advantage:
Write only 1 function. Default param is given automatically (text replacement in function calls).
MsgBox() example would need to write 5 C functions (for 0,1,2,3,4 args), where 1 function would be enough
with default parameters. The old way with writing many functions for "[optional]" arguments is still there,
so both ways can co-exist for compatibility.
Not necessary to mix them IMO. Either use current way and write many functions or use new way with default parameters
and write one function for everything.

Tailbite would also benefit from it when tailbiting PB functions with default params. Instead generating many functions, you generate
only one function and set the default parameters in the .desc for the specific library.