Read single numbers from data file (LuaLaTeX)

Is it possible to read a number from data files?

How to read a file with luatex

I found the example above but I don't need the whole line at once.

I need somthing like:

read(file)
get(A)
get(B)
X=A+B
print(X)


Sorry for my bad English. :)

Here is my example but it doesnt work :/

\documentclass{scrartcl}
\usepackage{luatextra}
\usepackage{filecontents}

\begin{luacode}
filename = "testdata.dat"
for line in io.lines(filename) do
local tab = string.explode(line)
x=tab[1]
y=math.log10(tab[2])
tex.print('('..x..','..y..')')
end
tex.print('};')
end
\end{luacode}

\begin{document}
\begin{tikzpicture}
\begin{axis}

\end{axis}
\end{tikzpicture}
\end{document}


Removing the \\ doesnt work.

• The readarray package reads files and allows recall of individual data entries from the file. – Steven B. Segletes Apr 22 '13 at 15:52
• I'm trying to understand exactly what you want. Then, I would try an answer. Do you want a file filled with two columns of numbers (A and B), and be able to arbitrarily specify recall of those numbers from a file so they can be added? – Steven B. Segletes Apr 22 '13 at 16:00

\usepackage{filecontents} should be replaced by \usepackage{pgfplots}. \usepackage{luatextra} should be replaced by \usepackage{luacode}. You should also remove the two backslashes at {:

\documentclass{scrartcl}
\usepackage{pgfplots}
\usepackage{luacode}

\begin{filecontents*}{testdata.dat}
1.0 20
1.1 21
1.2 22
\end{filecontents*}

\begin{luacode*}
filename = "testdata.dat"
for line in io.lines(filename) do
local tab = string.explode(line)
x=tab[1]
y=math.log10(tab[2])
tex.print('('..x..','..y..')')
end
tex.print('};')
end
\end{luacode*}

\begin{document}
\begin{tikzpicture}
\begin{axis}