I have a table with values calculated with \directlua{}.
They are formatted with siunitx columns.
I want to turn some values bold or change their color.
It appears that the output of \directlua{} macros are formatted like raw text, not as the siunitx S column should do.
MWE:
% Latex program : luaLatex
\documentclass{article}
% *** Fonts ***
\usepackage{fontspec}
\setmainfont{Tex Gyre Schola}[Numbers={Proportional,OldStyle}]
% *** Tabular figures ***
\newfontfamily\TLFfont{Tex Gyre Schola}[Numbers={Monospaced,Lining}]
% *** siunitx ***
\usepackage{siunitx}
% french typesetting, 3-figures blocks
\sisetup{locale=FR,group-minimum-digits=4}
% font detection
\sisetup{detect-all}
% *** Lua percent sign ***
% https://tex.stackexchange.com/questions/436979/problem-with-string-format-directlua-and-tex-sprint
\makeatletter
\let\luaPercent@percentchar
\makeatother
% *** Rounding value ***
\newcommand{\roundingValue}{2}
% **
\usepackage{xcolor}
% *** Tabular bold / siunitx ***
% https://tex.stackexchange.com/questions/66253/siunitx-bold-single-numeric-cells
\usepackage{etoolbox}
\robustify\bfseries
\begin{document}
\sisetup{mode=text,text-rm=\TLFfont,unit-mode=text}
\begin{tabular}{lSSr}
& {raw text value} & {directlua value} & \
basic text & 1231.45 & \directlua{n=1231.45 tex.print(string.format("\luaPercent.\roundingValue f",n))} & right \
itshape & \itshape 1231.45 & \itshape \directlua{n=1231.45 tex.print(string.format("\luaPercent.\roundingValue f",n))} & wrong \
bfseries & \bfseries 1231.45 & \bfseries \directlua{n=1231.45 tex.print(string.format("\luaPercent.\roundingValue f",n))} & wrong \
color & \color{red}1231.45 & \color{red}\directlua{n=1231.45 tex.print(string.format("\luaPercent.\roundingValue f",n))} & wrong \
tex.sprint & & \color{red}\directlua{n=1231.45 tex.sprint(string.format("\luaPercent.\roundingValue f",n))} & wrong \
tex.cprint 11 & & \color{red}\directlua{n=1231.45 tex.cprint(11, string.format("\luaPercent.\roundingValue f",n))} & wrong \
\end{tabular}
\end{document}
I use an old style numbers font on purpose, to enhance the differences:

(source: toile-libre.org)
The only right formatted text is when no modifier is applied.
What am I missing here?
