lua-users home
lua-l archive

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


Since recently Lua has been trying to slim down (e.g. removing certain
math functions), perhaps it's time to remove dofile/loadfile, as they
can be trivially replaced with intuitive one-liners (using io.lines
features available since Lua 5.2):

loadfile:

assert(load(io.lines(f, 4096), "@"..f))

dofile:

assert(load(io.lines(f, 4096), "@"..f))()

Side note: I noticed that liolib.c:g_read will create a new userdata
(via luaL_Buffer) for each read in cases where the number of
characters to read exceeds LUAL_BUFFERSIZE (8192). This could be
optimized by associating a buffer with the io_readline closure or
perhaps even the file.

-- 
Patrick Donnelly