Lua script with Log

Hi, i have a problem with my code

Hi, i have used Lua but i have a problem when i recive datas of serial then i want a log file.
first I write in the serial port and I collect the answer in Result. I want all Result in a file as a log.

This is my script. Thanks.

port= "/dev/tty/1"           
serialout= io.open(port,"w")  
serialin= io.open(port,"r")   							
while true do 
	serialout:write("½".."@")
	Result= LeerSerial()
end


function LeerSerial()
		while true do

			serialData= serialin:read();serialin:flush()	

			if string.len(serialData)>0 then
				serData = serialData
			end

			if  string.len(serialData) == 0 then
				return serData
			end

		end
end

That doesn't look much like Arduino code.

HI,
please if you post code, use [ code ] tags (without the spaces) . can be inserted with the # button above the smilies

check - Programming in Lua : 21.1 -

sorry, I modify my post. I know that this isnt arduino code but I want use Lua to control Arduino by one external router.