lua-users home
lua-l archive

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

On 9 May 2016 at 17:19, Dan Christian <> 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)

-- ... --

if have_library then
    -- Use the library"bar")


You said pcall didn't work. Easy mistake to make is:
pcall(require("mylibrary")). Which is wrong, after you think about it
more :)