No dia 28/12/2017, às 18:47, Hans Hagen <pragma@wxs.nl> escreveu:\starttext
\startluacode
MP.mycode = { }
local elements = { }
function MP.mycode.loadelements(filename)
elements = { }
for line in io.lines(filename) do
elements[#elements+1] = { string.match(line, '(%S+)%s*(%S+)%s*(%S+)%s*(%S+)%s*(%S+)') }
end
end
function MP.mycode.nofelements()
mp.print(#elements)
end
function MP.mycode.getlabel(i)
mp.quoted(elements[i][1])
end
function MP.mycode.getoffset(i)
mp.pair(elements[i][2],elements[i][3])
end
\stopluacode
\startMPcode
lua.MP.mycode.loadelements("molecule.xyz") ;
for i=1 upto lua.MP.mycode.nofelements() :
label (lua.MP.mycode.getlabel(i),50 * lua.MP.mycode.getoffset(i)) ;
endfor ;
\stopMPcode
\startMPcode
def my_loadelements(expr name) =
lua.MP.mycode.loadelements(name) ;
enddef ;
vardef my_nofelements =
lua.MP.mycode.nofelements()
enddef ;
vardef my_label(expr i) =
lua.MP.mycode.getlabel(i)
enddef ;
vardef my_offset(expr i) =
lua.MP.mycode.getoffset(i)
enddef ;
my_loadelements("molecule.xyz") ;
for i=1 upto my_nofelements :
label (my_label(i),50 * my_offset(i)) ;
endfor ;
\stopMPcode
\stoptext