[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Is it time to remove dofile/loadfile? (was: Can a Lua module find out whether it is being required or dofiled?)
- From: Patrick Donnelly <batrick@...>
- Date: Thu, 24 Sep 2015 22:20:58 -0400
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