My apologies in advance for what is probably a trivial issue.
I have been trying to debug this MWE for a while now, and despite my best efforts (and an old MWE that still works to go off of), I was still unable to get it to work.
The following code should make a black circle, but it is erroring. Different errors occur depending on the debugs I put, so I don't know which one to copy.
sometimes I tostring() the metapost.getparameterset too. Worked before, and still does on the old MWE. I must be missing something.
\startluacode
local function sse(str)
if type(str) ~= "string" then
error("single_string_expression: expected a string, got " .. type(str) .. " (" .. tostring(str) .. ")")
end
local chunk, err = load(("return %s"):format(str), "expression", "t", math)
if not chunk then
error("Failed to parse expression: " .. tostring(str) .. "\nError: " .. tostring(err))
end
local ok, result = pcall(chunk)
if not ok then
error("Error evaluating expression: " .. tostring(result))
end
return result
end
function mp.test()
local x = sse(metapost.getparameterset("x"))
mp.print(("fill fullcircle shifted (%f,0) scaled 1cm ;"):format(x))
end
\stopluacode
\startMPdefinitions
presetparameters "set_test" [x="5"] ;
def test =
applyparameters
"set_test"
"do_set_test"
enddef ;
vardef do_set_test =
pushparameters "set_test" ;
lua.mp.test() ;
popparameters ;
enddef ;
\stopMPdefinitions
\starttext
\startMPpage
test[] ;
\stopMPpage
\stoptext

segment.filloptionsas the first argument, whereas the format string expects six numbers followed by a string at the end. I don’t rule out that this could cause an error.%fshould ifsegment.filloptionsis not a number.