5 Replies Latest reply on Apr 26, 2012 4:06 PM by johnrellis

    Problem with getmetatable() of SDK objects in LR 4 beta

    johnrellis Most Valuable Participant

      See this post in the LR 4 beta forum for an interesting issue that affects Debug.pp:

       

      http://forums.adobe.com/thread/947975

       

      Not sure where the best place to post it is, given the volume of messaging in that forum and that no employees seem to read this forum.  If I don't hear anything in a while, I'll incorporate my hypothesized workaround into Debug and publish a new version for the few people besides me who might be using it.

        • 1. Re: Problem with getmetatable() of SDK objects in LR 4 beta
          areohbee Level 5

          I use it

           

          PS - I have no clue more than you, so charge ahead I guess...

          • 2. Re: Problem with getmetatable() of SDK objects in LR 4 beta
            DawMatt Level 3

            Hi John,

             

            I think you used the right approach to raise this issue.

             

            My personal view is the "correct" solution to this issue is to provide a

            type() method for every SDK class, so you can call that instead. Will see

            what happens.

             

            Your workaround looks OK, though you might want to add a test for and call

            to the type() method where it is available. This would cut down on the

            number of unknown object types you have to report.

             

            Thanks,

            Matt

            • 3. Re: Problem with getmetatable() of SDK objects in LR 4 beta
              johnrellis Most Valuable Participant

              I don't think testing for a :type() method and then invoking it solves the problem reliably. Suppose Debug.pp() has a code fragment like this:

               

              if type (x.type) == "function" then

              local sdkType = x:type ()

               

              Without any way of knowing that "x" is in fact an SDK object, the method call x:type() could result in an error.  For example, "x" could be an object defined by the plugin, with a method :type() that requires arguments.  In that case, calling x:type() with no arguments would raise an error. To avoid that possibility, we could wrap the call to :type() with pcall, or we need some other reliable way of determining if an object is an SDK object. 

               

              Debug.pp() could require that any objects passed to it don't have a :type() method or, if they do, that it conforms to the SDK semantics, but that makes Debug.pp() less general and more fragile.  The debugging environment for the SDK is already very weak and tenuous, so as a principle, it's good to avoid further weakening whenever possible.  (It's too bad that Adobe felt compelled to disable most of the Lua debugging primitives.)

               

              Note that once we know that a value "x" is an SDK object, tostring(x) will return it's type (e.g. "LrFolder"), whether it's an old-style SDK object or a new-style SDK object.

              • 4. Re: Problem with getmetatable() of SDK objects in LR 4 beta
                JohnK UK

                Interestingly, this doesn't seem to be a problem with LR4 on OS X.  I have a plug that works perfectly well in LR 3.x on both Windows and OS X and in LR 4 on OS X, but which throws this error in LR 4 on Windows.

                • 5. Re: Problem with getmetatable() of SDK objects in LR 4 beta
                  johnrellis Most Valuable Participant

                  Hmm, I just tested LR 4.0 on Mac OS 10.7.3, and getmetatable() applied to an SDK object produces an error message, the same as on Windows:

                   

                  Capture.PNG

                  Are you sure about what you're observing?