lua-users home
lua-l archive

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


> Anybody can help?

Yes. Your code is almost correct, except that the definition of the
t.p function in file1 and its use in file2 are inconsistent.
Inside function new, you define a function t.p using the colon operator.
Remember that

  function t:p(params)
    print(params.name)
  end

Is just a syntactic sugar for that:

  function t.p(self, params)
    print(params.name)
  end

So there are really *two* parameters in that function. But then you
call it with a dot syntax f1.p(t)
The 'self' parameter receives the 't' argument, and 'params' receives nil.
To fix the problem, either make the call with a colon 'f1:p(t)' in
file2, or remove the colon call in file1 since it is useless.

BTW, you seem to be running Lua 5.2, and still using the deprecated
'module' function, moreover with its hated "package.seeall" feature.
I would highly recommend you to either explicitly export the module
table, or to use a local_ENV variable.