Lua does not print before reading a file

I had a problem getting Lua to print before running the file and reading it. This will print the lines "Reading file ..." and "File read!". but only after the getFileString () function completes. I want him to print "Reading a file ..." before it starts. I narrowed it down to a file: read ("* a"), which messed 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...") local file_all = getFileString(directory.."myFile.txt") print("File Read!\n") end main() 

Also, it didn't matter if I was functionalized or not. I should mention that this is noticeable since I am reading a 150 MB file.

+4
source share
1 answer

I think the result is just buffered. Try adding io.stdout:setvbuf('no') before printing, which should disable output buffering.

+6
source

Source: https://habr.com/ru/post/1442344/


All Articles