Lua 독립 실행형 및 외부 바이너리

Lua 독립 실행형 및 외부 바이너리

저는 LuaLaTex로 우리를 위한 작은 프로그램을 작성하고 있습니다. 그 목적은 주어진 uuid로 QR 코드를 생성하는 것입니다. qr 코드는 페이지에 인쇄되고 uuid는 pdf의 메타데이터에 저장됩니다.

texmf그럼에도 불구하고 내 문서의 클래스 파일이 호출할 수 있는 실행 파일을 폴더에 포함시키는 것이 더 낫다고 생각했습니다 . qrencode & convertQR 코드를 생성하려면 다음 lua 스크립트(Linux)를 사용합니다 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

이 스크립트를 독립형 실행 파일로 변환하려면 luastatic다음 스크립트를 사용했습니다 makeluaexec.

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

이를 통해 실행 파일이 있지만 여전히 종속성이 있으므로 qrencode & convert다른 Linux 시스템으로 이동할 때 도구를 설치해야 합니다. 이러한 도구를 내가 직접 생성한 실행 파일로 패키징하는 방법이 있습니까?

답변1

예. 이 qrencode프로그램은 단지 래퍼일 뿐입니다.libqrencode, convert명령은 단지 래퍼일 뿐입니다.이미지 마술사. 이러한 명령을 호출하는 대신 코드에서 직접 라이브러리 함수를 호출하십시오. 바인딩으로https://github.com/isage/lua-imagick그리고https://github.com/vincascm/qrencode이에 유용합니다. 그런 다음 을 호출할 때 luastatic관련 정적 라이브러리를 전달하면 됩니다.

관련 정보