|
Post by EmilHalim on Mar 29, 2016 13:45:20 GMT -5
Hi Tom
Is there a way to know the number of params those passed to a pluigin function . this will allow us to semulate defaulte params.
Example ======= suppose we have a function to set a color , it's name SetColor , so we can use it like this
1- SetColor(RGBA) 2- SetColor(int red,int green, int blue) 3- SetColor(int red,int green, int blue ,int alpha)
so in the SetColor function we can check that , how many numbre of params , if it is 1 then it is the first case , if it is 2 then it is the second case , and so on...
what do you think.
thanks.
|
|
|
Post by Tom Mulgrew on Mar 29, 2016 20:14:32 GMT -5
No there isn't. Basic4GL will only compile the function call if you supply the same number of parameters as you specified when you registered the function. (And the parameter types must be compatible. Can't pass in a string when a number is expected etc).
But it does support function overloading. So you could create different versions of the function and register them with the same BASIC function name. For example:
void SetColor(int r, int g, int b, int a) { // Do the work }
void DLLFUNC WrapSetColor(IDLL_Basic4GL_Runtime& basic4gl) { int r = basic4gl.GetIntParam(4); int g = basic4gl.GetIntParam(3); int b = basic4gl.GetIntParam(2); int a = basic4gl.GetIntParam(1); SetColor(r, g, b, a); }
void DLLFUNC WrapSetColor_2(IDLL_Basic4GL_Runtime& basic4gl) { int r = basic4gl.GetIntParam(3); int g = basic4gl.GetIntParam(2); int b = basic4gl.GetIntParam(1); SetColor(r, g, b, 255); // Defaulting alpha to 255 }
If you register these both as "SetColor":
// 4 parameter version calls WrapSetColor registry.RegisterVoidFunction("setcolor", WrapSetColor); registry.AddParam(DLL_BASIC4GL_INT); registry.AddParam(DLL_BASIC4GL_INT); registry.AddParam(DLL_BASIC4GL_INT); registry.AddParam(DLL_BASIC4GL_INT);
// 3 parameter version calls WrapSetColor_2 registry.RegisterVoidFunction("setcolor", WrapSetColor_2); registry.AddParam(DLL_BASIC4GL_INT); registry.AddParam(DLL_BASIC4GL_INT); registry.AddParam(DLL_BASIC4GL_INT);
Then "setcolor(50, 60, 70, 100)" (in your BASIC program) will call the WrapSetColor and "setcolor(50, 60, 70)" will call WrapSetColor_2.
|
|
|
Post by EmilHalim on Mar 30, 2016 9:41:43 GMT -5
Tom , that is great , will help a lot.
thanks for creating simple basic4gl.
|
|