Can I make ffi.load error nonfatal?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Iori Branford
Prole
Posts: 36
Joined: Wed Apr 13, 2016 3:53 pm

Can I make ffi.load error nonfatal?

Post by Iori Branford »

My project uses an external library that I want to make optional. If it can't load, I would like to continue on without using it rather than halt the program. Can I do this?

I can't just disable the LOVE error handler - that only makes it close the window rather than show the blue error screen.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Can I make ffi.load error nonfatal?

Post by slime »

You can use pcall.

Code: Select all

local status, lib = pcall(ffi.load, "mylibrary")
if status then
    lib.foo(bar)
end
Iori Branford
Prole
Posts: 36
Joined: Wed Apr 13, 2016 3:53 pm

Re: Can I make ffi.load error nonfatal?

Post by Iori Branford »

slime wrote:You can use pcall.

Code: Select all

local status, lib = pcall(ffi.load, "mylibrary")
if status then
    lib.foo(bar)
end
Thanks slime. Works for me.
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 49 guests