[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to properly initialize a module?
- From: Petite Abeille <petite.abeille@...>
- Date: Tue, 6 Dec 2011 20:36:15 +0100
On Dec 6, 2011, at 8:17 PM, Ezequiel García wrote:
> What's the difference between
> require 'foo'.func() and require 'foo' 'bar' ?
If a function parameter is a table or a string, you do not need to wrap it within parenthesis.
So...
local function foo( ... )
end
foo 'bar'
foo {}
foo( 'bar' )
foo( {} )
... are all equivalent.
You can also make a table callable (see metamethod __call).
In that case, require returns a callable table, to which you can pass a parameter, which don't need to be parenthesis if it's a string or table.
Therefore:
local myFoo = require 'foo' 'bar'
Magic :)