
\newpage
\section{Transfers} % (fold)
\label{sec:transfers}
\subsection{From Lua to tkz-euclide or TikZ} % (fold)
\label{sub:fom_lua_to_tkz_euclide_or_tikz}

In this section, we'll explore how to transfer points, Booleans, and numerical values.

\subsubsection{Points transfer} % (fold)
\label{ssub:points_transfer}
We utilize an environment \tkzname{tkzelements}  outside an  \tkzname{tikzpicture} environment which allows us to perform  all the necessary calculations. Then, we execute the macro \Imacro{tkzGetNodes} which transforms the affixes of the table |z| into  \tkzname{Nodes}. Finally, we proceed with the drawing.

At present, the drawing program is either \TIKZ\ or \pkg{tkz-euclide}. However, you have the option to use another package for plotting. To do so, you'll need to create a macro similar to \tkzcname{tkzGetNodes}. Of course, this package must be capable of storing points like \TIKZ\ or \pkg{tkz-euclide}. 

\vspace*{1em}

\begin{mybox}
\begin{Verbatim}
\def\tkzGetNodes{\directlua{%
   for K,V in pairs(z) do
      local n,sd,ft
      n = string.len(K)
      if n >1 then
      _,_,ft, sd = string.find( K , "(.+)(.)" )  
     if sd == "p" then   K=ft.."'" end 
     _,_,xft, xsd = string.find( ft , "(.+)(.)" ) 
     if xsd == "p" then  K=xft.."'".."'" end 
       end    
  tex.print("\\coordinate ("..K..") at ("..V.re..","..V.im..") ;\\\\")
end}
}
\end{Verbatim}
\end{mybox}
See the section In-depth Study \ref{sec:in_depth_study} for an explanation of the previous code.

The environment \tkzNameEnv{tkzelements} allows to use the underscore |_| and the macro \tkzcname{tkzGetNodes} allows to obtain names of nodes containing \tkzname{prime} or \tkzname{double prime}. (Refer to the next example)

\begin{minipage}{0.5\textwidth}
\begin{Verbatim}
\begin{tkzelements}
   scale = 1.2
   z.o   = point: new (0,0)
   z.a_1 = point: new (2,1)
   z.a_2 = point: new (1,2)
   z.ap  = z.a_1 + z.a_2
   z.app = z.a_1 - z.a_2
\end{tkzelements}
\begin{tikzpicture}
   \tkzGetNodes
   \tkzDrawSegments(o,a_1 o,a_2 o,a' o,a'')
   \tkzDrawSegments[red](a_1,a' a_2,a')
   \tkzDrawSegments[blue](a_1,a'' a_2,a'')
   \tkzDrawPoints(a_1,a_2,a',o,a'')
   \tkzLabelPoints(o,a_1,a_2,a',a'')
\end{tikzpicture}
\end{Verbatim}
\end{minipage}
\begin{minipage}{0.5\textwidth}
\begin{tkzelements}
   scale = 1.2
   z.o   = point: new (0,0)
   z.a_1 = point: new (2,1)
   z.a_2 = point: new (1,2)
   z.ap  = z.a_1 + z.a_2
   z.app = z.a_1 - z.a_2
\end{tkzelements}
\hspace{\fill}
\begin{tikzpicture}
   \tkzGetNodes
   \tkzDrawSegments(o,a_1 o,a_2 o,a' o,a'')
   \tkzDrawSegments[red](a_1,a' a_2,a')
   \tkzDrawSegments[blue](a_1,a'' a_2,a'')
   \tkzDrawPoints(a_1,a_2,a',o,a'')
   \tkzLabelPoints(o,a_1,a_2,a',a'')
\end{tikzpicture}
\hspace{\fill}
\end{minipage}%

\newpage
% subsection fom_lua_to_tkz_euclide_or_tikz (end)
\subsubsection{Other transfers} % (fold)
\label{ssub:other_transfers}

Sometimes it's useful to transfer angle, length measurements or boolean. For this purpose, I have created the macro (refer to \ref{sub:transfer_from_lua_to_tex})  
\IEmacro{tkzUseLua(value)}

\begin{Verbatim}
\begin{tkzelements}
   z.b = point:  new (1,1)
   z.a = point:  new (4,2)
   z.c = point:  new (2,2)
   z.d = point:  new (5,1)
   L.ab = line : new (z.a,z.b)
   L.cd = line : new (z.c,z.d)
    det = (z.b-z.a)^(z.d-z.c)
    if det == 0 then bool = true 
      else bool = false
    end
    x = intersection (L.ab,L.cd)
\end{tkzelements}

The intersection of the two lines lies at
    a point whose affix is:\tkzUseLua{x}

\begin{tikzpicture}
  \tkzGetNodes
  \tkzInit[xmin =-1,ymin=-1,xmax=6,ymax=3]
  \tkzGrid\tkzAxeX\tkzAxeY
   \tkzDrawPoints(a,...,d)
   \ifthenelse{\equal{\tkzUseLua{bool}}{true}}{
   \tkzDrawSegments[red](a,b c,d)}{%
   \tkzDrawSegments[blue](a,b c,d)}
    \tkzLabelPoints(a,...,d)
\end{tikzpicture}
\end{Verbatim}

\begin{tkzelements}
z.b = point:  new (1,1)
z.a = point:  new (4,2)
z.c = point:  new (2,2)
z.d = point:  new (5,1)
L.ab = line : new (z.a,z.b)
L.cd = line : new (z.c,z.d)
det = (z.b-z.a)^(z.d-z.c)
if det == 0 then bool = true 
  else bool = false
end
x = intersection (L.ab,L.cd)
\end{tkzelements}

The intersection of the two lines lies at
a point whose affix is: \tkzUseLua{x}

\vspace{1em}
\hspace{\fill}
\begin{tikzpicture}
 \tkzGetNodes
 \tkzInit[xmin =-1,ymin=-1,xmax=6,ymax=3]
 \tkzGrid\tkzAxeX\tkzAxeY
 \tkzDrawPoints(a,...,d)
 \ifthenelse{\equal{\tkzUseLua{bool}}{true}}{
 \tkzDrawSegments[red](a,b c,d)}{%
 \tkzDrawSegments[blue](a,b c,d)}
 \tkzLabelPoints(a,...,d)
\end{tikzpicture}
  \hspace{\fill} 
% subsubsection other_transfers (end)
% subsubsection points_transfer (end)
% section transfers (end)

\endinput