lua-users home
lua-l archive

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


Miles Bader wrote:
For a while, I've tended to use require like:

   local XX = require 'whatever'

This seems to work with almost every module I've tried it with, and
offers a nice sense of locality.

[The alternative, of course, is to assume the loaded package will
put a "whatever" entry in _G.]

However I've just realized that some things _don't_ return an
appropriate table from require.  In particular swig-generated interfaces
seem to simply return the string "whatever"!  I could swear this _used_
to work with swig-generated interface, but it's been some months since I
last did something that would test that.

So, what exactly _is_ the recommended way to do this?  Is swig being bad
by returning a string instead?  Should I change my style of using

Can't comment on swig, but I'm using your style. In addition, I'm writing my lua code as modules too (learned this style from Petite Abeille's code):

local xx = require"xxxx"
local setmetatable = setmetatable
local require = require
local print = print

local function fa() print"yyyy.fa" end
local function fb() print"yyyy.fb" end

--simulate ctor
function __call(self, ...)
  local t = {}
  t.a = fa
  -- not public! t.b = fb
  return t
setmetatable(_M, _M)

local Y = require"yyyy"
local y = Y()



Hakki Dogusan