Method doesn't compile when defined in a mixin, but is fine without?

pineapple via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 1 06:32:27 PDT 2016


I'm working on an SDL wrapper based on the derelict sdl2 and 
opengl3 bindings and so I've got a method like this I wrote:

@property Vector2!int minsize(){
     int x, y;
     SDL_GetWindowMinimumSize(this.window, &x, &y);
     return Vector2!int(x, y);
}

I've got several almost identical methods for maximum size, and 
window size, and window position, and so I thought I'd make a 
mixin to cut down on the redundancy.

So I made my mixin, which looks like this - having definitions 
for both the getter above and also setters that seem to work fine:

static string vectorpropertymixin(string name, string SDL_getter, 
string SDL_setter){
     return "
         @property Vector2!int " ~ name ~ "(){
             int x, y;
             " ~ SDL_getter ~ "(this.window, &x, &y);
             return Vector2!int(x, y);
         }
         @property void " ~ name ~ "(in Vector2!int vector){
             this.set" ~ name ~ "(vector.x, vector.y);
         }
         void set" ~ name ~ "(in int x, in int y){
             " ~ SDL_setter ~ "(this.window, x, y);
         }
     ";
}

And then I put this in the class body, replacing the non-mixin 
getters that compiled without incident:

mixin(vectorpropertymixin(
     "minsize", "SDL_GetWindowMinimumSize", 
"SDL_GetWindowMinimumSize"
));

And using the mixin I get this error when attempting to compile:

E:\Dropbox\Projects\d\mach\sdl\window.d-mixin-285(295): Error: 
function pointer SDL_GetWindowMinimumSize (SDL_Window*, int*, 
int*) is not callable using argument types (SDL_Window*, 
const(int), const(int))

What's going on here? I feel like I must be making a really 
stupid obvious oversight.



More information about the Digitalmars-d-learn mailing list