lua-users home
lua-l archive

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


Hi

> I don't see a whole lot of use for this, if a module fails to load retrying is not going to help much in almost all use cases, except where you're loading components on demand. In that case I would suggest writing a wrapper around 'require' to get the behavior needed.

In a previous life I wrote a system where the lua app could require a particular module and, if the require failed, request that the module  be loaded from a depot and then re-require it. 
Although I share the opinion of  Gé Weijers, your approach is quite reasonable.  Since it is not standard, I would still throw an error when there is any failure in require.  This is what Lua demands from developers.

The download-and-install functionality was in a separate module - we did not modify the require code in the PUC-Rio lua source due to project requirements.
Yes, this is an extension :-)

> Another downside of returning 'false' is that you have to test the return value of each 'require',

Isn’t it good programming practice to always check return values?
In case of require, I won't check, except in extreme cases.  As someone already mentioned, there is no error message from require, so it is useless to check the return value.  I think require should throw an error, as Gé mentioned.

Regards,
Tomás