lua-users home
lua-l archive

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


Hi list !

I am wondering if there is anything wrong when defining "classes" in this way (without using module):

======== file lk.Dir ===============================
local lib = {sep = '/', ignore_pattern = '^[.]', type='lk.Dir'}
lib.__index = lib
lk.Dir = lib

setmetatable(lib, {
  -- new method
 __call = function(table, arg)
  local instance = {path = arg}
  setmetatable(instance, lib)
  return instance
end})

-- private
local function some_helper(self, x, y)
  -- ...
end

-- public
function lib:glob(pattern)
  -- ...
end

--- etc
======== file lk.Dir ===============================