File opening bug...?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
Elxx
Posts: 16
Joined: Wed Dec 07, 2005 4:48 pm
Contact:

File opening bug...?

Post by Elxx »

I'm working on my PSP web server, and it seems there is an interesting bug where it seems that any modifications made to files loaded by io.open (or io.input) will not exactly display right. It seems that it somehow stores the file size in a cache of some sort, and refuses to load anything beyond that. For example, if I have a file with the content:

Code: Select all

Hello world.
I load it with LuaPlayer, and it outputs just that. And I then modify it to make it read:

Code: Select all

Hello big world.
But when loaded in the same program, even if I properly closed the old one and everything, it will output:

Code: Select all

Hello big wo
The 4 extra bytes added to the middle somehow seem to 'push out' the last 4 bytes at the end.

It seems to all work fine in my PC's Lua interpreter, so I suspect the bug may be somewhere within LuaPlayer. Any ideas?

Here's the code for the portion of the app that loads the file...anything else I make of the sort exhibits the same problem.

Code: Select all

function parse_lhp(fname)
	output = ""
	code = ""
	res = ""
	cp = false
	lines = nil
	line = nil

	file = io.input(fname, "rb")

	for line in io.lines() do

		if string.find&#40;line, "%<%?"&#41; ~= nil then
			cp = true
		end

		if cp == true then
			if string.find&#40;line, "%<%?"&#41; == nil and string.find&#40;line, "%?%>"&#41; == nil then
				code = code .. line
			end
		else
			output = output .. line
		end
		
		if string.find&#40;line, "%?%>"&#41; ~= nil and cp == true then
			cp = false
			res = run_lua&#40;code&#41;
			output = output .. res
		end

	end

	file&#58;close&#40;&#41;

	return output
end
			
function run_lua&#40;code&#41;
	local result,err = loadstring&#40;code&#41;
	if not result then
		return "<br />Error&#58; " .. err
	else
		result, err = pcall&#40;result&#41;
		if not result then
			return "<br />Error&#58; " .. err
		else
			return "<br />Parsed."
		end
	end
end
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

it's very easy to get corrupt files while using usb mode..

usb should be deactivated before reading or writing any files from within a script.
Chaosmachine Studios: High Quality Homebrew.
modsyn
Posts: 28
Joined: Tue Sep 27, 2005 6:02 am

Post by modsyn »

didn't see any USB code in there, and i don't think a web server needs to use it, so i doubt that is the problem at all. i wish i could help, but sadly i can just
suggest this: have you tried:

Code: Select all

for line = io.lines&#40;fname&#41; do
instead of

Code: Select all

   file = io.input&#40;fname, "rb"&#41;

   for line in io.lines&#40;&#41; do
however, the reason i'm replying is to ask if you are adding the ability to
run LUA scripted dynamic pages. that would be really neat if you are. i
hope you get it worked out.
Elxx
Posts: 16
Joined: Wed Dec 07, 2005 4:48 pm
Contact:

Post by Elxx »

chaos wrote:it's very easy to get corrupt files while using usb mode..

usb should be deactivated before reading or writing any files from within a script.
I thought you just need to deactivate when writing files...hmm.

Modsyn, I have already tried that, but thanks.
modsyn wrote:however, the reason i'm replying is to ask if you are adding the ability to
run LUA scripted dynamic pages. that would be really neat if you are. i
hope you get it worked out.
Yes I am. :)
The one reason I was wanting to look into this bug is because it would make dynamic page testing maybe a bit frustrating if you had to restart the server each time you changed a file. But it's still beta and all, so people will have to live with it.
Post Reply