What you’re trying is not possible but there are other ways to check the content of the variable in Lua.
\startluacode
userdata = userdata or { }
function userdata.checkvariable(variable)
if variable == "" then
context("EMPTY")
else
context("NOT EMPTY")
end
end
\stopluacode
\setvariable{wagner}{name}{Wagner Macedo}
\starttext
\ctxlua{userdata.checkvariable("\getvariable{wagner}{name}")}
% This does only with \startlua or \ctxlua
\startlua
local name = "\getvariable{wagner}{name}"
if name == "" then
context("No Text")
else
name = "Name: " .. name
context(name)
end
\stoplua
\stoptext
A different method is to save the \setvariables entries in a Lua table and check the entries of the table.
\startluacode
userdata = userdata or { }
userdata.macedo = userdata.macedo or { }
userdata.macedo.data = { }
function userdata.macedo.savevariables(variables)
userdata.macedo.data = variables
end
function userdata.macedo.checkvariables()
local variables = userdata.macedo.data
-- check for name
if variables.name == "" then
context("Name: No name set")
context.par()
else
context("Name: "..variables.name)
context.par()
end
-- check for address
if variables.address == "" then
context("Address: No address set")
context.par()
else
context("Address: "..variables.address)
context.par()
end
end
\stopluacode
\starttexdefinition SaveVariables
\startlua
userdata.macedo.savevariables{
name = "\getvariable{macedo}{name}",
address = "\getvariable{macedo}{address}",
}
\stoplua
\stoptexdefinition
\setvariables[macedo][set=\SaveVariables]
\starttext
\setvariables[macedo][name=Wagner Macedo]
\ctxlua{userdata.macedo.checkvariables()}
\setvariables[macedo][address=Secret]
\ctxlua{userdata.macedo.checkvariables()}
\stoptext