In freebasic, for code
#macro DeclareEx(_name_)
declare function _name_##ExNew(byval x as long, byval y as long, byval w as long, byval h as long, byval title as const zstring ptr=0) as _name_##Ex ptr
declare sub _name_##ExDelete (byref ex as _name_##Ex ptr)
#endmacro
if we call DeclareEx(Fl_Button) then we get the 2 procedure
declare function Fl_ButtonExNew(byval x as long, byval y as long, byval w as long, byval h as long, byval title as const zstring ptr=0) as Fl_Button ptr
declare sub Fl_ButtonExDelete (byref ex as Fl_ButtonEx ptr)
how can we do that in nim? I have tried template and macro.
template Kitten*(name: string) =
var name_1 = "Mike"
Kitten("q")
echo q_1
says
a.nim(6, 6) Error: undeclared identifier: 'q_1'
at same time
macro Kitten*(name: string) : untyped =
var name_1 = "Mike"
Kitten("q")
echo q_1
says
a.nim(2, 7) Hint: 'name_1' is declared but not used [XDeclaredButNotUsed]
a.nim(6, 6) Error: undeclared identifier: 'q_1'
thnaks
This should do what you want:
template Kitten* (name: untyped) = # The type is untyped here, not string
var `name 1` {.inject.} = "Mike" # note: no underscore character, but a space instead.
# macros and templates are hygenic, so we need the inject pragma to allow the template to
# "dirty" the program by inserting a new symbol into it.
Kitten(q)
# note: no quotes here. It's an identifier, not a string.
# This corresponds to the "untyped" above.
echo q_1