HashTables and the like quite easy usable for any type I realized that
there could be a better way to make template functions. By implementing
a compiler directive - whatever name it shall be called, e.g. TypeOf() -
you could check by CompilerIf and the like whether a variable is of a
specific type or not. As such thing is defined _before_ runtime it can be
used as compiler directive.
A small example for usage could this:
Code: Select all
Macro MakeFunction(type)
Procedure.type Add#type(a.type, b.type)
CompilerIf TypeOf(a, #PB_COMPILER_TYPE_STRING)
ProcedureReturn Str(Val(a) + Val(b))
CompilerElse
ProcedureReturn a + b
CompilerEndIf
EndProcedure
EndMacro
Macro Add(a, b)
Add#TypeOf(a)(a, b)
EndMacro
MakeFunction(l)
MakeFunction(s)
Debug Add(5, 6)
Debug Add("5", "6")
#True or #False if two parameters are passed or the Type of the Variable
if only one was passed.