3 Replies Latest reply: Jan 11, 2012 7:00 PM by Matt Dawson RSS

    SDK: getmetatable of SDK objects raises error

    John R. Ellis CommunityMVP

      In LR 3, getmetable(o), where o is an SDK object (e.g. an LrFolder), would return a string naming the type of that object (e.g. "LrFolder").  In LR 4 beta it raises an error:

       

      plug-ins can not access metatables for tables created by the Lirghtroom SDK

       

      This causes a problem for debugging, since a general print function capable of printing any object (e.g. my Debugging Toolkit Debug.pp) needs a way to determine whether an object is an SDK object and of printing as much information about that object as possible.  Debug.pp is perhaps my single most productive development aid.

       

      Is this restriction on getmetatable() really needed?  What bad behavior by plugin authors does it prevent?

       

      Is a workaround is to use this function?

       

      function isSDKObject (value)

          return pcall (getmetatable, value)

          end

       

      Catching undocumented errors is always fraught with peril, and it is probably significantly slower than the LR 3 way.  (Speed of Debug.pp is important, since several plugins use it to save complex values persistently in files.).  Is there a better way to tell if a value is an SDK object?