Re: Tables and Import

2020-06-30 Thread tanguymario
Ok, I also tried replacing this line: 


var imgTable: Table[string, Image]


Run

by this one: 


var imgTable: Table[string, Image.Image]


Run

And it still gives the same error.

Anyway I will change the module names


Tables and Import

2020-06-30 Thread tanguymario
Hello,

I am doing a simple test with tables and have problems using import.

I have a file Image.nim:


type
   Image* = ref object of RootObj
  filepath*: string


Run

And a main file:


import tables
import Image

var imgTable: Table[string, Image]

imgTable["hello"] = Image(filepath: "world")

echo imgTable["hello"].filepath


Run

When compiling I have the following issue:

_main.nim(6, 9) Error: type mismatch: got _

Why my value type is recognized as void ? Image type seems to be recognized...

I am using nim 1.2.0


Re: Tables and Import

2020-06-30 Thread tanguymario
Yes it works that way, thanks!

But it is strange the type can be created but cannot be recognized in as the 
Table value type, isn't it ?


Re: OOP question

2020-04-11 Thread tanguymario
Thank you very much! 


OOP question

2020-04-10 Thread tanguymario
Hello,

I am quite new to nim language and started to develop a graphic app in web 
(using canvas / webgl).

I know nim is not OOP based but I still tried to achieve OOP using 'method'. 
But when I use two arguments using 'method' it does not work..

Am I wrong ? Or would there be better ways to implement that in nim ?

Thanks


type
   Drawable* = ref object of RootObj
   
   Sprite* = ref object of Drawable
   
   Graphics* = ref object of Drawable
   
   Renderer* = ref object of RootObj
   
   Renderer2D* = ref object of Renderer
   
   RendererWebGL* = ref object of Renderer

# OOP works here with one argument
method printType*(d: Drawable) {.base.} =
   echo "Drawable"

method printType*(s: Sprite) =
   echo "Sprite"

method printType*(g: Graphics) =
   echo "Graphics"

# When using multiple arguments OOP is not working
method render*(r: Renderer, d: Drawable) {.base.} = discard

method render*(r: Renderer2D, d: Drawable) = discard

method render*(r: Renderer2D, g: Sprite) =
  # Do not go here...
   echo "Renderer2D Sprite"

method render*(r: Renderer2D, g: Graphics) {.base.} =
  # Do not go here...
   echo "Renderer2D Graphics"

var arr: seq[Drawable]

let sprite1 = Sprite()
let graphics1 = Graphics()
arr.add(sprite1)
arr.add(graphics1)

var renderer: Renderer
renderer = Renderer2D()

for e in arr:
   e.printType()
   renderer.render(e)



Run