lua-users home
lua-l archive

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


Hallo,
	I've ran into a problem while trying to read from a file in a
standalone script with Lua 4.0b. What I intend to do is read from a file,
modify some values and write the new file with another name.
	The problem is that after reading the first line and writing the
unmodified line to another file, the write function won't write anything
else to the file. A snippet of the beginning of the file is (the file is
huge):

--- cut here
-1.508434 -0.069696 0.986861 2.844349
49 58
1.000000
0.101000
0.112000
0.000000 0.000000
-- cut here

but the new file only has the first line, although "49, 58" gets written
to the screen. What am I missing? The script (unfinished) follows:

-- cut here
#!/usr/local/bin/lua -f

function die(msg, code)
	-- Shows optional message
	if(msg) then
		print(msg)
	end
	-- clean up environment
	readfrom()
	writeto()
	-- exits gracefully (or tries to)
	cd = code or 0
	exit(cd)
end

-- anything to do?
if not arg[1] then
	die("Usage: " .. arg[0] .. " Acudes-file")
end
-- Our terrain file to be modified
filename = arg[1]
newfile  = "new-" .. filename
print("Modifying file " .. filename .. " into " .. newfile .. "...")
-- Opening streams
if not readfrom(filename) or not writeto(newfile) then
	die("Error opening input or output file... bailing out!", 1)
end
-- Copying first line (corners)
write(read())
-- Read & write grid dimensions
nx = read("*n") ny = read("*n")
write(nx, ny, "\n")
print("Grid dimensions: " .. nx .. ", " .. ny)
-- Copying the scale
write(read())

Cheers,

  --Alex	asandro@lcg.dc.ufc.br		Lab. de Computacao Grafica/UFC
+----------------------------------------------------------------------------+
|"Minha força vem da solidão. Não tenho medo das chuvas tempestuosas nem das |
| grandes ventanias soltas, pois eu também sou o escuro da noite."	     |
|	- Clarice Lispector						     |
+----------------------------------------------------------------------------+