|
Post by EmilHalim on Apr 9, 2016 11:20:52 GMT -5
Hi Tom,
I have those two function,
extern GLuint __cdecl Image_Create(cairo_surface_t* sur);
void DLLFUNC Func_Image_Create2(IDLL_Basic4GL_Runtime &basic4gl)
{
basic4gl.SetIntResult(Image_Create((cairo_surface_t*)basic4gl.GetIntParam(1)));
}
extern GLuint __cdecl Image_Create(GLuint tex);
void DLLFUNC Func_Image_Create3(IDLL_Basic4GL_Runtime &basic4gl)
{
basic4gl.SetIntResult(Image_Create((GLuint)basic4gl.GetIntParam(1)));
}
So how Basic4Gl will call the correct one from basic Code ?, i mean 'cairo_surface_t*' will be just int type.
BTW there is no reason for add another param , they only need one param.
|
|
|
Post by Tom Mulgrew on Apr 9, 2016 23:25:59 GMT -5
So how Basic4Gl will call the correct one from basic Code ?, i mean 'cairo_surface_t*' will be just int type. Sorry, Basic4GL doesn't handle that. Like you say, if they both have the same name and same parameters then there's no way for it to know which one to call. You'll have to make something about them different.
|
|
|
Post by EmilHalim on Apr 10, 2016 12:20:56 GMT -5
Oh that Bad News.
any way do you plain to implement this ?
thanks for you help.
|
|
|
Post by Tom Mulgrew on Apr 11, 2016 2:47:18 GMT -5
Oh that Bad News. any way do you plain to implement this ? thanks for you help. I'm not sure what could be implemented. If you have two identical functions with the same name and parameter types, there's no way to know which one you're trying to call. Although, one thing you could try is creating a structure to wrap your cairo_surface_t* pointer. E.g.: #pragma pack(push,1) struct SSurface { cairo_surface_t* surface; }; #pragma pack(pop) Then your plugin can declare a matching BASIC structure in your ::Load method, and use it as a parameter to your function: ssurfaceHandle = registry.RegisterStructure("ssurface", 1, 0); registry.AddStrucField("surface", DLL_BASIC4GL_EXT_INT);
//...
registry.RegisterFunction("Image_Create",Func_Image_Create2, DLL_BASIC4GL_INT); registry.AddStrucParam(ssurfaceHandle); // Using structure handle returned from RegisterStructure(...) Now you have an Image_Create function that takes a single parameter which is a BASIC structure of type SSurface. A structure is different to an integer, so Basic4GL will know which function you want to call. You can access the structure like this: void DLLFUNC Func_Image_Create2(IDLL_Basic4GL_Runtime &basic4gl) { SSurface surfaceParam; basic4gl.SetType(ssurfaceHandle); // This tells GetParam that we are accessing a SSurface structure basic4gl.GetParam(1, &surfaceParam); // Read BASIC SSurface into C++ SSurface object // Now you can do something with it basic4gl.SetIntResult(Image_Create(surfaceParam.surface)); } If you want to return a structure from one of your functions, you can declare the function (in the ::Load method) like: registry.RegisterStructureFunction("Get_Surface", Func_Get_Surface, ssurfaceHandle); // Register parameters etc...
Then to return the value, you would use: void DLLFUNC Func_Get_Surface(IDLL_Basic4GL_Runtime &basic4gl) { SSurface surfaceResult; surfaceResult.surface = [get surface from somewhere]
basic4gl.SetType(ssurfaceHandle); // This tells SetReturnValue that we are accessing a SSurface structure basic4gl.SetReturnValue(&ssurfaceResult); // Convert C++ SSurface into BASIC SSurface and return } It takes a little bit of work to setup, but it should solve your function overloading problem. And you also get some type safety, in that you can only assign BASIC structure values to variables/parameters of the same structure type. Btw this code is all off the top of my head, and it has been a while since I've looked at the plugin DLL stuff. I may not have got it 100% correct, but you should hopefully get the gist of it
|
|