lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi!
 
i have no idea what your test program should be doing, but i suggest using print instead of write.
print doesn't choke on other values than strings or numbers, and it automatically adds the newline at the end.
i can also offer this function, since you seem to be having problems with visualizing tables:
 
-- print entire table
function dump(table)
 if type(table) == "table" then
  local indizes = {}
  foreach(table, function(i,v) tadd(%indizes, i) end)
  if getn(indizes) == 0 then
   print("<empty table>")
  else
   sort(indizes)
   foreachi(indizes, function(_, index)
    local value = %table[index]
    if type(index) == "string" then
     print(index .. ":\t" .. tostring(value))
    else
     print("[" .. index .. "]\t" .. tostring(value))
    end
   end)
  end
 else
  print(table)
 end
end
hope this helps,
Peter
-----Original Message-----
From: owner-lua-l@tecgraf.puc-rio.br [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Volkan Civelek
Sent: Tuesday, October 30, 2001 9:23 AM
To: Multiple recipients of list
Subject: question

Hi,

This is my first email and fyi i am very new born in Lua.

Now the question is;

why does the below code gives me

"error: bad argument #1 to `write' (string expected, got nil)
stack traceback:
   1:  function `write' [C]
   2:  main of file `ask.lua' at line 10

Error: Script failed"

this???

--case.lua

function foo (rt, from, s)
 for i=1,10 do
  tinsert (rt, from, strsub(s,i,i+1))
 end
end
local combi = {}
local var1 = {"1234567890"}
foo(combi, 34, var1[1])
write (combi[34], "\n")
write (combi[35], "\n")  --this guy has a problem

--EOF

and combi[34] writes 0 ??

TIA
Volkan



Do You Yahoo!?
Make a great connection at Yahoo! Personals.