Skip to content

Docs: personal scripts and Flatpak luarc limitations not documented (5.6.0) #697

Open

Description

@NohWayJose

Summary

Several behaviours that affect anyone writing personal Lua startup scripts under Darktable 5.6.0 (Flatpak, Linux) are undocumented or incorrect in the current README. Discovered through hands-on debugging. Submitting as a doc issue in case it is useful to others or to the maintainers for a README update.


1. Lua version is 5.4, not the host system version

Darktable 5.x bundles its own interpreter. The system lua -v (often 5.1 or 5.3) is irrelevant. Confirmed for 5.6.0 Flatpak:

flatpak run --command=find org.darktable.Darktable /app -name "liblua*.so.*"
# → /app/lib/liblua.so.5.4.6

goto, <const>, bitwise operators all work inside Darktable scripts.


2. require "myscript" in the user luarc silently fails under Flatpak

The README's "Enabling" section says to add require "myscript" to the user luarc. This works for native installs but silently does nothing under Flatpak.

Why: Darktable Flatpak ships a system luarc (/app/share/darktable/luarc) that loads tools/script_manager. Because script_manager detects it is running from the system data directory (system_based = true), the user's ~/.var/.../config/darktable/luarc is loaded via loadfile() rather than require(), and at that point the Lua package.path does not include the user lua/ directory. Any require "myscript" in the user luarc silently fails — no error, no load.


3. The correct approach: personal/ subfolder + darktablerc entry

script_manager scans USER_LUA_DIR but only processes scripts that are inside a named subfolder (the pattern requires at least one /). A .lua file placed directly in lua/ is silently ignored.

Working approach:

mkdir -p ~/.var/app/org.darktable.Darktable/config/darktable/lua/personal
cp myscript.lua ~/.var/app/org.darktable.Darktable/config/darktable/lua/personal/

Then add one line to darktablerc:

lua/script_manager/personal/myscript=TRUE

Key format: lua/script_manager/<folder>/<script-name-without-.lua>.

The script can also be enabled through the Darktable UI (Lua Scripts panel → personal folder → toggle), which writes the darktablerc entry automatically.


4. dt.films.new(path) creates empty film rolls — use dt.database.import(path) instead

dt.films.new(path) creates the film_roll database entry but does not scan for images. The resulting roll is empty. Darktable prunes empty film rolls on exit, so the call appears to succeed (no Lua error) but nothing persists after the session.

dt.database.import(path) is the correct call when the intent is to import images:

-- When given a directory path, returns a table of imported image objects
local ok, result = pcall(dt.database.import, path)
if ok then
    local n = type(result) == "table" and #result or (result ~= nil and 1 or 0)
    -- n images imported, film roll created with content
end

5. Minimal working template for a personal startup script

-- lua/personal/myscript.lua
-- Loaded by script_manager; runs when lighttable becomes active.

local dt = require "darktable"

local function run()
    -- dt.films, dt.database.import, etc. are all ready here
end

dt.register_event("myscript", "view-changed",
    function(event, old_view, new_view)
        if new_view.id == "lighttable" and
           (old_view == nil or old_view.id == "none") then
            pcall(run)
        end
    end
)

6. Debugging gotcha: Snap/Flatpak LD_LIBRARY_PATH crash

On systems with Snap installed, running flatpak run org.darktable.Darktable -d lua from a terminal may crash immediately:

symbol lookup error: /snap/core20/current/lib/x86_64-linux-gnu/libpthread.so.0:
    undefined symbol: __libc_pthread_init, version GLIBC_PRIVATE

Workaround:

env -u LD_LIBRARY_PATH flatpak run org.darktable.Darktable -d lua 2>&1 | grep lua

Suggested README additions

  • Note under the Flatpak section that require "myscript" only works for scripts inside the cloned lua-scripts repository; personal scripts need the personal/ subfolder + darktablerc approach.
  • A brief "Personal Scripts" subsection covering the above.
  • A note in the API docs (or script_manager docs) that dt.films.new() does not import images and dt.database.import() should be used instead.

Happy to help draft specific text if useful.

Activity

  1. wpferguson commented on Jul 12, 2026

    @wpferguson
    Member

    The darktable Lua documentation is at https://darktable-org.github.io/luadocs/


    Now I'll address the issues you raised...

    1. darktable has been on Lua 5.4 since darktable 3.8.0. The specific version of darktable 5.4 is dependent on the system that darktable is built on since it links in the Lua library (Ubuntu 22.04 - 5.4.4, Ubuntu 24.04 - 5.4.6). I'm not sure what version of Lua 5.4 flatpak links when it is built.

    1. I created a script, test.lua in the user lua directory. In the luarc file I had one line, require "test", and the script was found and ran fine.
         2.0151 LUA INFO: script_manager.lua:  processing tools/executable_manager 
         2.0156 LUA INFO: script_manager.lua:  processing tools/get_libdoc 
         2.0160 LUA INFO: script_manager.lua:  processing tools/get_lib_manpages 
         2.0163 LUA INFO: callback: finished processing scripts 
         2.0163 LUA bare test script in user lua directory
         2.0214 LUA INFO: script_manager.lua:  processing test 
         2.0214 LUA INFO: script_manager.lua:  processing wpferguson/adjust_time 
         2.0216 LUA INFO: script_manager.lua:  processing wpferguson/correct_lens 
         2.0218 LUA INFO: script_manager.lua:  processing wpferguson/dxo_photolab 
         2.0221 LUA INFO: script_manager.lua:  processing wpferguson/export2collection 
         2.0222 LUA INFO: script_manager.lua:  processing wpferguson/postsharpen 
         2.0224 LUA lua dir is /app/share/darktable/lua-scripts
    

    The script simply printed a line, bare test script in user lua directory.


    1. You don't need to add a line to the darktablerc file. As you can see in the log snippet above the user lua directory gets parsed and the scripts added to script_manager. Scripts that aren't in a sub directory are not added, but can be run using the user luarc file.

    1. The documentation referenced above clearly states that darktable.films.new doesn't import images. It also includes a link to darktable.database.import.

    1. This is just wrong and can cause a darktable crash because it will deliberately trip over a race condition in darktable initialization. https://github.com/wpferguson/darktable-lua-scripting-aids contains boilerplate code and code snippets to help people get started

    1. I just did flatpak run org.darktable.Darktable -d lua and it worked with no problems on Ubuntu 24.04 and some of the output is pasted above.

    The README is probably going to get changed to just a link to the luadocs, rather than trying to maintain documentation in 2 places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions