lua-users home
lua-l archive

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



> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org]
> On Behalf Of steve donovan
> Sent: vrijdag 28 september 2012 9:36
> To: Lua mailing list
> Subject: Re: require() multiple parameters
> 
> On Fri, Sep 28, 2012 at 7:08 AM, Rena <hyperhacker@gmail.com> wrote:
> > require("bread", "butter", "jelly")
> 
> It's not a difficult function to write:
> 
> function nrequire(...)
>    local args = {...}
>    for i,mod in ipairs(args) do
>       args[i] = require(mod)
>    end
>   return unpack(args)
> end
> 
> And its module could be organized so that you could say:
> 
> local bread,butter,jelly = require 'multi' ('bread','butter','jelly')
> 
> (Yes, require() _can_ return multiple values but that's rather unusual)
> 
> steve d.

Obviously true, not so hard to implement. But the question was (at least my
interpretation of it) why Lua doesn't do that by default?

One thing that comes to mind is how to handle errors; in the example, if
'butter' either isn't available or throws an error, what to return then?
'bread' has already been setup, maybe did some initialization, in the return
values there is only 1 slot for the failed 'butter', so no possibility to
return nil + error. And finally, should 'jelly' be handled or not, because
of the order it might depend on 'butter'.

Thijs