I wanted to customize a log procedure, and add log levels which would log the message or not depending on the log level. The proc looks like:
proc log(level: LogLevel, args: varargs[JsObject, toJs]) =
discard
I wanted to call console.log from the jsconsole package, but if I pass it a seq, it is not unwrapped. is there ant way to have it unwrapped.
Other languages typically have a specific syntax (*, ...) to tell the compiler to unrwap the array when calling the procedure. Is there a similar thing in Nim. Perhaps it's a macro ?
Thank you.
Thank you, I didn't think I'd need to use macros but I succeeded with:
import macros
macro log_macro(level: LogLevel, message: string, args: varargs[untyped]): untyped =
result = newCall("log", newIdentNode("console"), message)
for i in 0 ..< args.len:
result.add args[i]
template log(level: LogLevel, message: string, args: varargs[untyped]) =
log_macro(level, "[" & $level & "] " & message, args)