Skip to content

Instantly share code, notes, and snippets.

@exelotl
Created September 11, 2018 23:40
Show Gist options
  • Save exelotl/03c23322c4237b873a68f018516dfaae to your computer and use it in GitHub Desktop.
Save exelotl/03c23322c4237b873a68f018516dfaae to your computer and use it in GitHub Desktop.
using type conversion syntax to choose the desired version of an overloaded function
proc foo(x:int) = echo "int ", x
proc foo(x:string) = echo "string ", x
var p1:pointer = (proc(x:int){.nimcall.})(foo) # p1 gets the int version of foo
var p2:pointer = (proc(x:string){.nimcall.})(foo) # p2 gets the string version of foo
var f1 = cast[proc(x:int){.nimcall.}](p1)
var f2 = cast[proc(x:string){.nimcall.}](p2)
f1(100)
f2("boo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment