Skip to content

Instantly share code, notes, and snippets.

@Araq
Created February 7, 2016 22:28
Show Gist options
  • Select an option

  • Save Araq/03629a7e9e4da243c59f to your computer and use it in GitHub Desktop.

Select an option

Save Araq/03629a7e9e4da243c59f to your computer and use it in GitHub Desktop.
type
VTable = object
methodA: proc (this: MyObject; a, b: int)
methodB: proc (this: MyObject; a, b: string)
OtherObject = object
fieldA: int
fieldB: int
MyObject = object
vtab {.delegate(this).}: ptr VTable
other {.delegate.}: OtherObject
var obj: MyObject
obj.methodA(3, 4)
# is rewritten to:
obj.vtab.methodA(obj, 3, 4)
# also possible:
obj.fieldA
# rewritten to:
obj.other.fieldA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment