lua-users home
lua-l archive

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

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>")
   foreachi(indizes, function(_, index)
    local value = %table[index]
    if type(index) == "string" then
     print(index .. ":\t" .. tostring(value))
     print("[" .. index .. "]\t" .. tostring(value))
hope this helps,
-----Original Message-----
From: []On Behalf Of Volkan Civelek
Sent: Tuesday, October 30, 2001 9:23 AM
To: Multiple recipients of list
Subject: question


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"



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


and combi[34] writes 0 ??


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