Page 1 of 1

[Question]Where is the bug?

Posted: Wed Apr 24, 2013 9:30 am
by nikneym

Code: Select all

anadosyam="oku.gr";
ac=io.open(anadosyam, "r+");

while true do
  actir=ac.read(ac, "*a");
  
  if not line then
    break;
  end
end

acilacakdosya=actir;
  acilacak=io.open(acilacakdosya,"r");

  while true do
    kodlar=acilacak.read(acilacak, "*a");

    if not line then
      break;
    end
  end
İt prints:

Code: Select all

Program starting as '"lua" -e "xpcall(function() io.stdout:setvbuf('no'); require('mobdebug').loop('nikneym-MS-7507',8172) end,function(err) print(debug.traceback(err)) end)"'.
Program 'lua' started in '/home/nikneym/Desktop/Html5-OyunMotoru/html5' (pid: 3271).
Debugging session started in '/home/nikneym/Desktop/Html5-OyunMotoru/html5/'.
Debugging session completed (traced 0 instructions).
Program completed in 0,39 seconds (pid: 3271).
main.lua:29: attempt to index global 'acilacak' (a nil value)
stack traceback:
	main.lua:29: in main chunk

Where is the bug?

Re: [Question]Where is the bug?

Posted: Wed Apr 24, 2013 1:16 pm
by Plu
My guess would be that the program either failed to read a filename into "actir", or the file it tries to read does not exist. Try getting the error from io.open and printing it:

Code: Select all

acilacak, error =io.open(acilacakdosya,"r");
if acilacak == nil then
  print( error )
end
Or something along those lines. See also http://www.lua.org/pil/21.2.html

Re: [Question]Where is the bug?

Posted: Wed Apr 24, 2013 2:25 pm
by Robin
This might not directly be involved in the error you get, but the following occurs twice in your code:

Code: Select all

  if not line then
    break;
  end
The problem is, you never assign anything to line. It seems you copied that from somewhere else. I would replace

Code: Select all

while true do
  actir=ac.read(ac, "*a");
 
  if not line then
    break;
  end
end
by

Code: Select all

actir=ac.read(ac, "*a");
and do the same for the other bit.