lua-users home
lua-l archive

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


On 2023-11-28 18:44, nobody wrote:
A full checklist of the above: (x --> y here means x __indexes to y, i.e. `setmetatable( x, { __index = y } )`)
[…]
  *  load = (thin wrapper that defaults to env not _G for the environment)

Of course, that one should also be `env.load`… and I completely forgot about `loadfile` and `dofile`, so add:

 *  env.loadfile = (wrapper of `loadfile` that defaults to `env` instead of `_G`)
 *  env.dofile = (reimplementation that uses `env` not `_G`)


And while I'm sending a second mail anyways: your `ext.lua` might be better suited to be loaded using `dofile`, which doesn't cache things.

With `x = 999` in `ext.lua`:
- after `require "ext" ; x = 1 ; require "ext"`, x = 1
- after `dofile "ext.lua" ; x = 1 ; dofile "ext.lua"`, x = 999

-- nobody