Skip to content

Instantly share code, notes, and snippets.

@hakanderyal
Created April 10, 2015 11:21
Show Gist options
  • Save hakanderyal/0c5a0c4b02b60c40dac1 to your computer and use it in GitHub Desktop.
Save hakanderyal/0c5a0c4b02b60c40dac1 to your computer and use it in GitHub Desktop.
type
GenericSceneObj* = ref object
SceneNode* = ref object
children*: seq[SceneNode]
parent*: SceneNode
sceneObj*: GenericSceneObj
GameObj* = ref object
name: string
AnotherGameObj* = ref object
health: int
# I want to make GameObj and AnotherGameObj to be compatible with GenericSceneObj,
# so I can store them in SceneNode
# Is it possible without inheriting from GenericSceneObj?
# I've tried using user defined type classes,
# but couldn't get them to work (probably using them in a wrong way)
type
GenericSceneObj* = concept x
draw(x)
SceneNode* = ref object
children*: seq[SceneNode]
parent*: SceneNode
sceneObj*: GenericSceneObj
proc newSceneNode* (sceneObj: GenericSceneObj): SceneNode =
result = SceneNode(sceneObj: sceneObj)
newSeq(result.children, 10)
proc attachChild* (this: SceneNode, child: SceneNode) =
child.parent = this
this.children.add(child)
# udtc_test.nim(16, 18) Error: invalid type: 'GenericSceneObj' in this context: 'proc (SceneNode, SceneNode)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment