lua-users home
lua-l archive

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




On 26 Jun 2018, at 13:13, Kenneth Lorber <keni@his.com> wrote:



On Jun 23, 2018, at 8:57 AM, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:

"Kenneth" == Kenneth Lorber <keni@his.com> writes:

Kenneth> require() seems to silently accept extra arguments. Is this a
Kenneth> bug?

Pretty much every function accepts and silently ignores extra arguments,
unless the function itself bothers to check for them and throw an
explicit error.

--
Andrew.

Thanks, and after a little source diving you are correct, but that's not quite the reply I was looking for.

Is there some reason this is a language feature?  Some use-case I don't see?  (If so, why is there the occasional check for extra arguments?)

Is it documented somewhere I missed?

Is there any reason not to add checks for extra arguments?  If it's performance, it could be available as a compile time option.

I'm working for an implementation for 5.3.4.  If there's any interest please let me know or I'll just quietly add it to my copy and stop bothering the list about it.

Thanks,
Keni

To me it is about flexibility, multiple return values, and the ability to only take what is needed. Eg:

   take_two(return_three())

Without a bunch of locals. Why would you even want to limit that and make it an error? It takes flexibility away.

For example: take OpenResty, it uses a lot of those extra checks and it's a pita. See this code for example:

https://github.com/Kong/kong/blob/82a51c4b519728eed4f957fdaa547ed4abea9332/kong/globalpatches.lua#L296-L302

The last argument “socket options” must be a table, not even `nil` is accepted. Hence in the calling code it requires an if-then construct.

So be careful what you wish for with those checks.

Thijs