{"id":2226,"date":"2012-02-09T10:28:48","date_gmt":"2012-02-09T10:28:48","guid":{"rendered":"http:\/\/www.readytext.co.uk\/?p=2226"},"modified":"2013-11-28T09:05:37","modified_gmt":"2013-11-28T09:05:37","slug":"luacom-connecting-luatex-to-windows-automation","status":"publish","type":"post","link":"https:\/\/www.readytext.co.uk\/?p=2226","title":{"rendered":"LuaCOM: connecting LuaTeX to Windows automation"},"content":{"rendered":"<h1>Introduction<\/h2>\n<p>The Windows operating system provides a technology called COM, which stands for Component Object Model. In essence, it provides a way for software components and applications to &#8220;talk to each other&#8221;. That&#8217;s a gross oversimplification but it gives the general idea. It&#8217;s now an old technology but nevertheless it is still very powerful; over the years I&#8217;ve used it quite extensively for automating various publishing\/production tasks. In those days it was with Perl using a module called <a href=\"http:\/\/search.cpan.org\/~jdb\/Win32-OLE-0.1709\/lib\/Win32\/OLE.pm\">Win32::OLE<\/a>. <\/p>\n<p>Of course, applications have to be written to support COM so you can think of COM-aware applications as offering a &#8220;set of services&#8221; that you can call &#8212; many applications provide the ability to call those services from scripting languages which have support for COM (via modules\/plugins etc), such as Perl, Ruby and, of course, Lua via LuaCOM. A combination of COM-aware applications and scripting languages with COM support provides a very flexible way to &#8220;glue together&#8221; all sorts of different applications to create novel automated workflows\/processes. <\/p>\n<p>Using COM from within scripting languages is fairly straightforward but under the surface COM is, to me anyway, a complex beast indeed. The best low-level COM programming tutorials I have ever read are published on <a href=\"http:\/\/www.codeproject.com\">codeproject.com<\/a>, written by Michael Dunn. Here&#8217;s one such tutorial <a href=\"http:\/\/www.codeproject.com\/Articles\/633\/Introduction-to-COM-What-It-Is-and-How-to-Use-It\">Introduction to COM &#8211; What It Is and How to Use It<\/a>.<\/p>\n<h2>LuaCOM<\/h2>\n<p>LuaCOM lets you use COM in your Lua scripts, i.e., it is a binding to COM. I don&#8217;t know if there are freely available builds of the latest version (probably with Windows distributions of Lua), but you can download and compile the latest version from <a href=\"https:\/\/github.com\/davidm\/luacom\/\">Github<\/a>. <\/p>\n<p>LuaCOM is a DLL (Dynamic Link Library) that you load using the standard &#8220;require&#8221; feature of Lua. For example, to start Microsoft Word from within your Lua code, using LuaCOM, you would do something like this:<\/p>\n<pre class=\"brush: plain; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\ncom = require(&quot;luacom&quot;)\r\n-- should be CreateObject not GetObject!\r\nWord =com.CreateObject(&quot;Word.Application&quot;)\r\nWord.Visible=1\r\ndoc = Word.Documents:Open(&quot;g:\/x.docx&quot;)\r\n<\/pre>\n<p>Naturally, the Microsoft Office applications have very extensive support for COM and offer a huge number of functions that you can call should you wish to automate a workflow process via COM from within Lua. For example, you can access all the native equation objects within a Word document (read, write, create and convert equations&#8230;). If you have watched <a href=\"https:\/\/www.readytext.co.uk\/?p=1861\">this video<\/a> and wondered how I got LuaTeX and Word to talk to each other, now you know: LuaCOM provided the glue.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The Windows operating system provides a technology called COM, which stands for Component Object Model. In essence, it provides a way for software components and applications to &#8220;talk to each other&#8221;. That&#8217;s a gross oversimplification but it gives the general idea. It&#8217;s now an old technology but nevertheless it is still very powerful; over [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,3,21],"tags":[],"class_list":["post-2226","post","type-post","status-publish","format-standard","hentry","category-luatex-c-code-windows-dlls","category-luatex","category-microsoft-word"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2226"}],"version-history":[{"count":10,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2226\/revisions"}],"predecessor-version":[{"id":4009,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2226\/revisions\/4009"}],"wp:attachment":[{"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.readytext.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}