2 Replies Latest reply on Jan 10, 2017 1:57 PM by LoweMo.photo

    Any technical benefit to compiling Lua?

    DFBurns Level 1

      If I'm not interested in hiding my source code, is there any other technical benefit to compiling my plugin's source code to .luac files?

        • 1. Re: Any technical benefit to compiling Lua?
          johnrellis Most Valuable Participant

          I'm guessing that compiled code loads faster, though for typical plugins, the difference is probably negligible.

           

          I can't think of any other benefits, though perhaps someone else can.

          • 2. Re: Any technical benefit to compiling Lua?
            LoweMo.photo Level 1

            This is from the lua.org luac manual page, which does provide a brief discussion of the advantages of precompiling:

            The main advantages of precompiling chunks are: faster loading, protecting source code from accidental user changes, and off-line syntax checking.

             

            Precompiling does not imply faster execution because in Lua chunks are always compiled into bytecodes before being executed. luac simply allows those bytecodes to be saved in a file for later execution.

             

            Precompiled chunks are not necessarily smaller than the corresponding source. The main goal in precompiling is faster loading.

            I hope that answers your question. Off the top of my head, I'd have really just said, "What John said" … but I guess there are some other (minor) advantages....

             

            Do bear in mind that the page also discusses what might be a disadvantage of precompiling your lua source:

            The internal format of the binary files produced by luac is likely to change when a new version of Lua is released. So, save the source files of all Lua programs that you precompile.

            While Lightroom has only supported Lua 5.1.4 for several versions (of Lightroom) now, it's possible (or at least, "not impossible") that they could decide to move to a a more recent version of Lua (there are certainly some improvements to the language which have come in since 5.1.4), in which case, any compiled code would need to be recompiled for the newer version of Lua. This is a theoretical downside, IMHO. (I don't think this is very likely, since it would break backward compatibility (and forward compatibility for old plugins with a newer version of LR.) I think it's more likely that Adobe might totally refactor and make the plugin system support, e.g. a web interface (i.e. something that allows building an interface with HTML/CSS/Javascript, etc) that might provide alternative handles for connecting to Lightroom (hopefully without removing the support for the old plugins, all at once). That would make it much easier for most of us to design our plugins and provide a lot of visual nice-to-haves. Or Adobe could just move to one of the other scripting languages they use (more broadly) in Adobe products. Even if Lua does have some advantages for ease of integration with a C++ program, it is kind of an odd-ball language (paired with an even odder SDK), which means there aren't so many of us who have bothered to figure out how to craft a decent LR plugin. (Compare that to the number of Web developers who write plugins for Wordpress or modules for Drupal, both of which have huge developer communities!) If they wanted to make this more accessible, I could imagine moving from Lua altogether.

             

            In any event, I think it should be pretty obvious that if you compile your code, you want to make sure to keep your original source code safely tucked away where you still have it for any fixes and/or for recompiling (with a newer version of luac) or for reading and refactoring/translating (in the event of a total technology shift).