Hi,
I have an exported template which is logically should be called only as a top level statement in other modules. If it is incidentally called inside a proc it breaks thread safety (template changes global var). And this is multithreaded application, nim code is single threaded but wrapping C project is multithreaded.
I would like to enforce the contract with somehing like:
when not isTopLevel:
{.error: "Template should be invoked only from top level"}
Any ideas how similar can be achieved?
Thanks
Check out this hack:
template testScope =
template ret = return
when compiles(ret()): echo "Function"
else: echo "Wild West"
proc test = testScope()
test()
testScope()
Not fully tested. Adapted to your needs https://pastebin.com/U8LfDA0Z