First off, thank you for the quick response.
> note that a lot of languages do not support multiple inheritance for a good
> reason (outside the scope of this question), so how would you use those?
In fact I see that my question is not strictly Nim-related but I'm actually
asking for help on how to do stuff without multiple inheritance in general. I
hope that's not a problem
By the way, I read the code you proposed but I have a few doubts. If I'm
understanding it correctly, the procs "renderTargetWithTexture" and
"renderTargetWithWindow" will convert from a texture/window object to an
abstract render target object. But does that mean I'll have to allocate a new
AbstractRenderTarget on the heap (and assign it data from the texture/window I
got in) each time I have to convert one of those? Wouldn't that slow down
things a bit? Also because I was thinking about an API like this:
let mainWindow: Window = newWindow(..)
let myRectangle: Rectangle = newRectangle(...)
let myTexture: Texture = newTexture(..)
myTexture.draw(myRectangle)
window.draw(myTexture)
In my mind I imagine RenderTargets having a draw method that accepts any
Drawable object and Drawable object having a drawOn method that accepts a
RenderTarget. The drawOn method of the Drawable objects would do the hard work,
while the draw method of RenderTargets would simply be something like
proc draw(rt: RenderTarget, obj: Drawable):
obj.drawOn(rt)
just to make (IMHO) the API syntax cleaner for someone using the library (like
the first code snipped).
But if I had, for instance, hundreds of rectangles, textures, etc... every time
I call the _draw_ method on an object I would have to run the converter and
allocate another object on the heap... right...?