www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Method doesn't compile when defined in a mixin, but is fine without?

reply pineapple <meapineapple gmail.com> writes:
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.
May 01 2016
next sibling parent pineapple <meapineapple gmail.com> writes:
Strangely, though I'm getting this error when wrapping 
SDL_GetWindowMinimumSize and SDL_GetWindowMaximumSize, I don't 
get any compilation errors wrapping the identically-signatured 
SDL_GetWindowSize and SDL_GetWindowPosition using the same mixin.
May 01 2016
prev sibling parent reply ag0aep6g <anonymous example.com> writes:
On 01.05.2016 15:32, pineapple wrote:
 static string vectorpropertymixin(string name, string SDL_getter, string
 SDL_setter){
[...]
 mixin(vectorpropertymixin(
      "minsize", "SDL_GetWindowMinimumSize", "SDL_GetWindowMinimumSize"
 ));
Should the second one be "SDL_SetWindowMinimumSize" here? ("Set" instead of "Get".)
May 01 2016
parent reply pineapple <meapineapple gmail.com> writes:
On Sunday, 1 May 2016 at 13:46:14 UTC, ag0aep6g wrote:
 On 01.05.2016 15:32, pineapple wrote:
 static string vectorpropertymixin(string name, string 
 SDL_getter, string
 SDL_setter){
[...]
 mixin(vectorpropertymixin(
      "minsize", "SDL_GetWindowMinimumSize", 
 "SDL_GetWindowMinimumSize"
 ));
Should the second one be "SDL_SetWindowMinimumSize" here? ("Set" instead of "Get".)
See, of course it was going to be something stupid like that. Would be nice if compile errors were kinder to mixins, might've realized where the error actually was. Any tips on that?
May 01 2016
parent Stefan Koch <uplink.coder googlemail.com> writes:
On Sunday, 1 May 2016 at 14:01:51 UTC, pineapple wrote:
 On Sunday, 1 May 2016 at 13:46:14 UTC, ag0aep6g wrote:
 On 01.05.2016 15:32, pineapple wrote:
 static string vectorpropertymixin(string name, string 
 SDL_getter, string
 SDL_setter){
[...]
 mixin(vectorpropertymixin(
      "minsize", "SDL_GetWindowMinimumSize", 
 "SDL_GetWindowMinimumSize"
 ));
Should the second one be "SDL_SetWindowMinimumSize" here? ("Set" instead of "Get".)
See, of course it was going to be something stupid like that. Would be nice if compile errors were kinder to mixins, might've realized where the error actually was. Any tips on that?
Write code into a file or wait for my ctfe-debug tool.
May 02 2016