lua-users home
lua-l archive

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


Jerome Vuarand <jerome.vuarand@gmail.com> writes:
> You can use newindex to perform something similar :
>
> local _M = {}
> local _ENV = setmetatable({},{__index=_ENV, __newindex=_M})
> function foo()
> end
> return _M

cute!

Hmm, even nicer, the boilerplate bits are all at the beginning and end,
so, I could even write my own little "require" analogue that automates
such a pattern for my own modules, using `loadin' to do the loadin'... :]

function my_load_module (name)
  local m = {}
  local env = setmetatable({},{__index=_ENV, __newindex=m})
  loadin (env, name)
  return m
end

hmmm

-Miles

-- 
Monday, n. In Christian countries, the day after the baseball game.