[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to ignore module not found
- From: Dan Christian <danchristian65@...>
- Date: Mon, 9 May 2016 09:43:17 -0700
Doh, newbie mistake. I put in pcall(require('zlib')), when it should
have been: pcall(require, 'zlib')
Thanks for setting me straight,
Dan
On Mon, May 9, 2016 at 9:25 AM, Matthew Wild <mwild1@gmail.com> wrote:
> On 9 May 2016 at 17:19, Dan Christian <danchristian65@gmail.com> wrote:
>> How do I make require() not cause a stack trace when a module is not found?
>
> ----------------------
>
> local have_library, library = pcall(require, "mylibrary")
>
> -- Do something if the library was not found, if you want
> if not have_library then
> print("Library was not found. Error:", library)
> end
>
> -- ... --
>
> if have_library then
> -- Use the library
> library.foo("bar")
> end
>
> ----------------------
>
> You said pcall didn't work. Easy mistake to make is:
> pcall(require("mylibrary")). Which is wrong, after you think about it
> more :)
>
> Regards,
> Matthew
>