Brilliant, that's exactly what I was looking for. I guess I had assumed 
new() would act as return and boot me out of the function, but that is not 
the case it seems. I find Julia so interesting!

On Thursday, May 7, 2015 at 4:19:10 AM UTC-4, Alex wrote:
>
>
>> Would it be possible to run the callback when I init a "mouse" object? I 
>> feel like it should be possible but I can't seem to figure out how to 
>> reference or pointer the object being initialized from within it's own 
>> constructor. Similar to the below, replacing thisObject for something?
>>
>> type Mouse
>>     position
>>
>>     function Mouse(window)
>>         position = (0.0,0.0)
>>         GLFW.SetCursorPosCallback(window, (x,y)->thisObject.position = (x
>> ,y))
>>
>>         new(position)
>>     end
>> end
>>         
>>  
>>
>> Sure, the key point is that `new(...)` returns the new instance. So in 
> your example it would be like 
>
> type Mouse
>     position
>
>     function Mouse(window)
>         position = (0.0,0.0)
>         self = new(position)
>
>         GLFW.SetCursorPosCallback(window, (x,y)->(self.position=(x,y); 
> nothing))
>         return self
>     end
> end
>
>
> I wouldn't use a Tuple to store the position though. Maybe Graphics.Vec2 
> is more suitable.
>
> - Alex.
>

Reply via email to