You need to decide if you coding in TeX or you still thinking in another computer language. I can gather from your comments such as "...drives me nuts", "...things go to hell in a handbasket real quick" that you have a hard time adapting. So I would suggest rather think in "Lua", move all your coding into the Lua part.
Here is an example that justs does and calculates happy numbers that might also make you a bit happier:)
All the typesetting has been moved onto a function in this case \boxit thus having a good separation of concerns; think the same way for your table, post a minimal and maybe the community can take it up from there.
\documentclass{tufte-book}
\usepackage[listings]{tcolorbox}
\lstloadlanguages{[LaTeX]TeX, [primitive]TeX,Pascal}
\usepackage{filecontents}
\usepackage{amsmath}
\usepackage{luacode} % loads luatexbase as well
\newcommand\emphasis[2][blue]{\lstset{emph={exec,if,then,else,do,end,while,for,print,sprint,directlua,#2},
emphstyle={\ttfamily\textcolor{#1}}}}%
\lstset{language={[LaTeX]TeX},
escapeinside={{(*@}{@*)}},
gobble=0,
stepnumber=1,numbersep=5pt,
numberstyle={\footnotesize\color{gray}},%firstnumber=last,
breaklines=true,
framesep=5pt,
basicstyle=\small\ttfamily,
showstringspaces=false,
keywordstyle=\ttfamily\textcolor{blue},
stringstyle=\color{orange},
commentstyle=\color{black},
rulecolor=\color{gray!10},
breakatwhitespace=true,
showspaces=false, % shows spacing symbol
backgroundcolor=\color{gray!15}}
\begin{document}
\emphasis{return,repeat,until,function,local}
\begin{tcblisting}{}
\begin{luacode}
-- example adapted from
-- http://rosettacode.org/wiki/Happy_numbers
function boxit(color, var, s)
return "\\fbox{\\strut\\color{violet} "..var.."} "
end
function digits(n)
if n > 0 then return n \% 10, digits(math.floor(n/10)) end
end
function sumsq(a, ...)
return a and a ^ 2 + sumsq(...) or 0
end
local happy = setmetatable({true, false, false, false}, {
__index = function(self, n)
self[n] = self[sumsq(digits(n))]
return self[n]
end } )
i, j = 0, 8
repeat
i, j = happy[j] and (tex.sprint(boxit(violet, j, " ")) or i+1) or i, j + 1
until i == 17 --or j > 999
\end{luacode}
\end{tcblisting}
\end{document}
\vspacewhen in normal text; in atabularenvironment it is\\[<dimen>]. Please edit your message, removing foul language. – egreg Mar 18 '12 at 14:18