[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to ignore module not found
- From: Matthew Wild <mwild1@...>
- Date: Mon, 9 May 2016 17:25:11 +0100
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