0

I am writing a small program to us in LuaLaTex. The purpose of it is to produce an qr-code with a given uuid, the qr-code is printed on the page and the uuid is stored in the pdf's meta-data.

Nevertheless I thought it would be nice to have a single executable in the texmf folder to called by the class file from my document. To generate the qr-codes i used (Linux) qrencode & convert with this lua script uuidqrcode.lua:

#!/usr/bin/env lua 

function gen_qr_uuid ()
    local uuid = require 'uuid'
    -- uuid.seed(math.randomseed(os.time()))
    local encode = uuid()
    local name = encode
    local format = 'pdf'

    local qrencode = string.format(
        [[qrencode \
            --type=EPS \
            --output=%s.eps \
            --size=10 \
            --level=H \
            --margin=0 \
            --casesensitive \
            %s \
            ]], 
            name,
            encode)

    local convert = string.format(
        [[convert \
            %s.eps \
            %s.%s \
            ]],
            name,
            name,
            format)

    local rmeps = string.format("rm %s.eps", name)

    os.execute(qrencode)
    os.execute(convert)
    os.execute(rmeps)
end

for i=1, (arg[1] or 1) do
    gen_qr_uuid ()
end

To convert this script to a standalone executable i used luastatic with this script makeluaexec:

#!/bin/sh
luastatic $1 `pkg-config --libs --cflags lua`

With this I have a single executable file but it sill depends on qrencode & convert, so when I move to a other Linux machine these tools has to be installed. Is there a way to pack these tools into my self generated executable?

0

Yes. The qrencode program is just a wrapper around libqrencode, and the convert command is just a wrapper around ImageMagick. Instead of calling those commands, call the library functions from your code directly. Bindings such as https://github.com/isage/lua-imagick and https://github.com/vincascm/qrencode will be useful for this. Then, when you call luastatic, just pass in the relevant static libraries.

  • Hi Joseph, thank you for the hint to these library's, after a little wiggle to install the lua-imagick on my centos machine (ImageMagick has to be a newer version, but they provide rpm's, so was not that big deal), I noticed that the lua library / binding of qrencode only provides suport for "ASCII and PNG" so there is no need anymore for the convert command. So i do not get the desired qr-code in pdf (vector) format. Basically I can work with the solution now, but back to my first question, is it possible to include a executable? – M117 Oct 5 '18 at 8:34
  • Not without a lot of trouble. It would be much easier to modify the qrencode bindings (or write new ones) so they support EPS. – Joseph Sible Oct 5 '18 at 13:10
  • I found this Embedding binary data in executables, maybe this works for this use case? I mean on lua-imagick they say: "FFI-based bindings are hackish and buggy" but are very convenient and already well documented. What do you think about this approach? Could it be done with writing a auxlib? – M117 Oct 5 '18 at 13:27
  • You could, but then you'd have to extract it from the binary into a temporary file to run it, then delete it when it's done, and you'd have to get/build statically-linked versions of the programs, or they'd fail due to missing dependencies. – Joseph Sible Oct 5 '18 at 13:39
  • Ok, I think this approach with binding these things into the executable is not the best way to go, better write a function which checks if the dependencies are available and if not exiting the program before running in a error. Thanks a lot for your help – M117 Oct 5 '18 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.