lua-users home
lua-l archive

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


One important thing is how easy it is to library writers to follow the
conventions. Mainly for Lua libraries, the conventions should be as
few (and as simple) as possible. Python is a good standard here:  The
library writer don't write anything at all to turn a "library" (a set of
definitions) into a package.

If the idea is for a package to receive the table where it should
register itself, why not use the environment itself to be that table?
So, the library simply defines its stuff "globally", and it goes
automatically to the desired table? Something like this:

  -- library code (in file libname)
  -- don't care about packages
  function foo ()  ... end      -- "global" function


  -- loading machinery  (in baselib?)
  local f = loadfile(libname)
  setfenv(f, X)   -- X is where we want to load that library
  f()             -- initialize the library into table X

-- Roberto