(Last Updated: August 7, 2020)

Best way to check for http_async?

  • I'm trying to implement the support for http_async in my Virtual Devices plugins. From my tests, Vera's UI seems less busy, but I want to automatically detect if it's installed. Right now I'm using a code like this one:

    if pcall(require, "http_async") then

    but I'm not sure it's the best way to do it. Any one? @akbooer? Thanks!

  • ok, so:

    local _, async = pcall(require, "http_async")
    if type(async) == "table" then

    seems to be way to do it. Leaving this post here for the future me 🙂

  • Yes, that's about it. Here's an example from openLuup's client.lua file:

    local OKmd5,md5 = pcall (require, "md5")                -- for digest authenication (may be missing)

    ...so then I can write:

        if not OKmd5 then
          return nil, "MD5 module not available for digest authorization"

    which very readable and understandable.

Log in to reply