Here is Lua code that prints the first nine fibonacci numbers:
local function fib(n)
f={1,1}
for i=3,9 do
f[i]=f[i-1]+f[i-2]
end
return(f[n])
end
for n=1,9 do print(fib(n)) end
Here is Context+Lua that prints 3 x 3 table of the first nine natural numbers:
\starttext
\setupTABLE[each][each][frame=off,align=left,width=4em,height=2em]
\startluacode
context.bTABLE()
for j = 0, 2 do
context.bTR()
for k = 1, 3 do
context.bTD()
context(3*j+k)
context.eTD()
end
context.eTR()
end
context.eTABLE()
\stopluacode
\stoptext
How can these be combined to print a 3 x 3 table of the first nine fibonacci numbers?
I have tried a couple of ways to iterate over the lua table f in the most indented line of context, looked at what pertinent threads I could find, the Wiki entries, CLD, and tried Aditya's method from Stack Exchange; I am missing something.
John