Lua is not printed before the file reads

Before running the opened and read file, I encountered the problem of getting Lua to print. This will print the strings “Reading File …” and “File Read!” but only in it After finishing the getFileString() function. I want it to print “Read file…” before running. I reduced it to a file: read(“*a”) This will mess up all the prints in my (larger) script .

function getFileString(path)

local file, err = io.open(path, "r")
local all = file:read("*a")
file:close()

return all

end

function main ()

local directory = "C:\Documents and Settings\All Users\Documents\"

print("Reading File...")< br /> local file_all = getFileString(directory.."myFile.txt")
print("File Read! ")

end

main( )

It doesn’t seem to matter whether I am functional or not. I should mention that this is mainly because I am reading about 150MB files.

I think the output is just buffering. Try adding io.stdout: setvbuf(‘no’) before printing, which should turn off output buffering.

< p>Before running the opened and read file, I ran into the problem of getting Lua to print. This would print the strings “Reading File…” and “File Read!” but only after it completed the getFileString() function. Hope it prints “Read file…” before running. I reduced it to file: read(“*a”) This will mess up all prints in my (larger) script .

function getFileString(path)

local file, err = io.open(path, "r")
local all = file:read("*a")
file:close()

return all

end

function main ()

local directory = "C:\Documents and Settings\All Users\Documents\"

print("Reading File...")< br /> local file_all = getFileString(directory.."myFile.txt")
print("File Read! ")

end

main( )

It doesn’t seem to matter whether I am functional or not. I should mention that this is mainly because I am reading about 150MB files.

I think the output is just buffering. Try to add io.stdout before printing: setvbuf(‘no’), this should turn off output buffering.

Leave a Comment

Your email address will not be published.