I have run the following code in LuaLatex. I'm doing everything on overleaf, if that matters.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,arrows.meta,graphs.standard}
\usegdlibrary{circular}
\begin{document}
\begin{tikzpicture}
\graph [
simple necklace layout, node distance=1.5cm,
nodes={draw,circle}
]
{
subgraph C_n [n=8];
\foreach \i in {1,...,5}{
\i -- \directlua{tex.sprint(3+\i)};
}
};
\end{tikzpicture}
\vspace{20 pt}
\begin{tikzpicture}
\graph [
simple necklace layout, node distance=1.5cm,
nodes={draw,circle}
]
{
subgraph C_n [n=8];
\foreach \i in {1,...,5}{
\i -- \directlua{tex.sprint(mod({3+\i},8))};
}
};
\end{tikzpicture}
\end{document}
The two Tikz pictures have the same code except that in the second loop, 3+\i is replaced by mod({3+\i},8)). Because 3 + i % 8 is equal to 3 + i for i = 1,...,4, I should have ended up with essentially the same picture both times. However, here is what I end up with:
How can I fix this code so that the modular arithmetic is evaluated correctly?
Once I have that working, the idea is to extend the loop to {1,...,8} in order to get the full "star".


mod({3+\i},8)is not valid Lua. Trymath.mod(3+\i,8). Also you fell for the typical LuaTeX gotcha:tex.sprint(<number>)will not do the correct thing. Always usetex.sprint(tostring(<number>)). – Henri Menke Dec 18 '20 at 09:42