I am struggling trying to understand how to actually use luacode* environment, so that I do not have to escape all the \ characters in the strings that Lua builds before sending to Tex.
The whole point of using luacode* vs. luacode is that one does not have to escape the \ inside lua strings before sending them to Tex. According to this table from https://www.ctan.org/pkg/luacode?lang=en

But when making a string and using tex.print, Latex gives error. So I am doing something wrong, or I do not understand something basic about this.
Here is a MWE
\documentclass{article}
\usepackage{luacode}
\begin{document}
\begin{luacode*}
i=6
j=8
tex.print("\begin{tabular}{|l|l|}\hline")
tex.print(i.."&"..j)
tex.print("\\\hline")
tex.print("\end{tabular}")
\end{luacode*}
\end{document}
lualatex foo.tex gives
(./foo1.aux)
! LuaTeX error [\directlua]:3: invalid escape sequence near '\h'.
\luacode@dbg@exec ...code@maybe@printdbg {#1} #1 }
l.13 \end{luacode*}
Only when escaping all the \ does it work:
\documentclass{article}
\usepackage{luacode}
\begin{document}
\begin{luacode*}
i=6
j=8
tex.print("\\begin{tabular}{|l|l|}\\hline")
tex.print(i.."&"..j)
tex.print("\\\\ \\hline")
tex.print("\\end{tabular}")
\end{luacode*}
\end{document}

I have looked at which-lua-environment-should-i-use-with-luatex-lualatex and printing-backslash-from-a-luacode-environment and do not see the solution for this. i.e. how to write the above code as is without having escape \ or do any other special processing. Since this is supposed to be the whole point of using luacode*. I do not want to write the code in an external file. I need to process it as shown above, but avoid having to escape \.
Using TL 2015.
*File List*
article.cls 2014/09/29 v1.4h Standard LaTeX document class
size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
luacode.sty 2012/01/23 v1.2a lua-in-tex helpers (mpg)
ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO)
luatexbase.sty 2013/05/11 v0.6 Resource management for the LuaTeX macro progr
ammer
luatex.sty 2010/03/09 v0.4 LuaTeX basic definition package (HO)
infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO)
etex.sty 2015/03/02 v2.1 eTeX basic definition package (PEB,DPC)
luatex-loader.sty 2010/03/09 v0.4 Lua module loader (HO)
luatexbase-compat.sty 2011/05/24 v0.4 Compatibility tools for LuaTeX
luatexbase-modutils.sty 2013/05/11 v0.6 Module utilities for LuaTeX
luatexbase-loader.sty 2013/05/11 v0.6 Lua module loader for LuaTeX
luatexbase-regs.sty 2011/05/24 v0.4 Registers allocation for LuaTeX
luatexbase-attr.sty 2013/05/11 v0.6 Attributes allocation for LuaTeX
luatexbase-cctb.sty 2013/05/11 v0.6 Catcodetable allocation for LuaTeX
luatexbase-mcb.sty 2013/05/11 v0.6 Callback management for LuaTeX
***********
(too few examples on the net showing how to use lua from inside Latex)
Tex->Luapart, since I am just looking atLua->Texnow. But if you are saying theluacode*is meant to apply for the "Tex->Lua" and not toLua->Texthen this makes using strings in Lua very hard if one have to escape all the "" each time. I can do all the above much easier in Python, without having to escape anything, using Pythonsr"""multi-line raw string support. So I am trying to understand why would I need to use Lua then in this case. – Nasser Jul 04 '15 at 21:31"...". You may want[[...]]. The latter is the equivalent (more or less) ofr"..."in Python. – Javier Bezos Jul 05 '15 at 17:47\documentclass{article} \usepackage{luacode} \begin{document} The following is my table \begin{luacode*} i=6; j=8; a = [[\begin{tabular}{|l|l|}\hline ]]..i.."&"..j..[[\\ \hline \end{tabular} ]]; print(a); tex.print(a); \end{luacode*} \end{document}I can do all this in Python using r""..."" so easily, I wonder why would I need to use Lua inside Latex for this. – Nasser Jul 06 '15 at 01:37