The way I've been defining key-value macros is to first pass them to Lua, handle the parsing there thanks to `utilities.parsers.settings_to_hash` and then assign the resulting Lua table to ConTeXt variables.
This worked fine up to now, but I'm having problems with the following MWE:
```
\def\style#1[#2] {
\ctxlua{userdata.style([==[#2]==])}
\placestyle
}
\startluacode
userdata = userdata or {}
userdata.style = function(keyvals)
local style = {
color = nil,
text = nil,
}
args = utilities.parsers.settings_to_hash(keyvals)
for k, v in pairs(args) do
style[k] = v
end
context.setvariables({'style'}, style)
end
\stopluacode
\define\placestyle{
\doiftext
{\getvariable{style}{text}}
{\color[\getvariable{style}{color}]{\getvariable{style}{text}}}
}
\starttext
\style[
text={Some red text},
color=red,
]
\style[
color=blue,
]
\stoptext
```
Here I assign a default value of `nil` to every key, and then check if the `text` variable is empty before printing it. I would expect the second macro not to print anything since its `text` should be nil, instead both macros print 'Some red text', the first one in red and the second one in blue.
I have attached a screenshot of the output.
What am I doing wrong?