On Thu, Aug 25, 2016 at 5:49 PM, Henri Menke
Hi Kumar,
the function job.variables.save seems to save the key in job.variables.collected.macros instead of job.variables.collected. The problem is that macros is not created unconditionally, which is why you might run into a »attempt to index a nil value« error without some manual error checking. Therefore I recommend assigning the temp value to job.variables.tobesaved["document:temp:"..name]. Perhaps Hans joins this discussion and schools me about why this could be a bad idea, but so far it works.
Also, I'd recommend making all your user level macros protected and check for the optional argument in \startwhatever (otherwise you'll get errors like »Macro doesn't match its definition«). Because I'm really cautious I also use \luaescapestring{#1} (Try for example »foo"bar« as a value without).
<snipped code> Indeed, this worked! I'll try to understand the internals myself to know what is going on exactly. Thanks for the solution. Kumar