From 1905be8577689c6e65aed4395fbb83504c60f567 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 6 May 2023 14:31:15 -0400 Subject: [PATCH 1/4] lib/dtutils.lua - added check_max_api_version to handle the case where part of the API is removed as in the case of the darktable.gui.libs.fixter functions. --- lib/dtutils.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/dtutils.lua b/lib/dtutils.lua index 0a6d441..dcc116a 100644 --- a/lib/dtutils.lua +++ b/lib/dtutils.lua @@ -69,6 +69,42 @@ function dtutils.check_min_api_version(min_api, script_name) end end +dtutils.libdoc.functions["check_max_api_version"] = { + Name = [[check_max_api_version]], + Synopsis = [[check the maximum required api version against the current api version]], + Usage = [[local du = require "lib/dtutils" + + local result = du.check_max_api_version(max_api, script_name) + max_api - string - the api version that the application was written for (example: "5.0.0") + script_name - string - the name of the script]], + Description = [[check_max_api_version compares the maximum api required for the appllication to + run against the current api version. This function is used when a part of the Lua API that + the script relies on is removed. If the maximum api version is not met, then an + error message is printed saying the script_name failed to load, then an error is thrown causing the + program to stop executing. + + Return_Value = [[result - true if the maximum api version is available, false if not.]], + Limitations = [[When using the default handler on a script being executed from the luarc file, the error thrown + will stop the luarc file from executing any remaining statements. This limitation does not apply to script_manger.]], + Example = [[check_max_api_version("9.0.0") does nothing if the api is less than or equal to 9.0.0 otherwise an + error message is printed and an error is thrown stopping execution of the script.]], + See_Also = [[]], + Reference = [[]], + License = [[]], + Copyright = [[]], +} + +function dtutils.check_max_api_version(max_api, script_name) + local current_api = dt.configuration.api_version_string + if max_api < current_api then + dt.print_error("This application is written for lua api version " .. max_api .. " or earlier.") + dt.print_error("The current lua api version is " .. current_api) + dt.print("ERROR: " .. script_name .. " failed to load. Lua API version " .. max_api .. " or earlier required.") + dt.control.sleep(2000) -- aqllow time for the error to display before script_manager writes it's error message + error("Mzximum API " .. max_api .. " not met for " .. script_name .. ".", 0) + end +end + dtutils.libdoc.functions["split"] = { Name = [[split]], Synopsis = [[split a string on a specified separator]], From e47672b4951f2e6d100bbddb528410d1beafd6a7 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 6 May 2023 14:36:22 -0400 Subject: [PATCH 2/4] lib/dtutils.lua - added delay in check_min_api_version to sllow display of the error message before script_manager displays an error message. --- lib/dtutils.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/dtutils.lua b/lib/dtutils.lua index dcc116a..ee9f4ee 100644 --- a/lib/dtutils.lua +++ b/lib/dtutils.lua @@ -65,6 +65,7 @@ function dtutils.check_min_api_version(min_api, script_name) dt.print_error("This application is written for lua api version " .. min_api .. " or later.") dt.print_error("The current lua api version is " .. current_api) dt.print("ERROR: " .. script_name .. " failed to load. Lua API version " .. min_api .. " or later required.") + dt.control.sleep(2000) -- aqllow time for the error to display before script_manager writes it's error message error("Minimum API " .. min_api .. " not met for " .. script_name .. ".", 0) end end From 9e0374d597a7ad17175aa01b556aa5ea6337d672 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 6 May 2023 14:56:58 -0400 Subject: [PATCH 3/4] lib/dtutils.lua - fix typos --- lib/dtutils.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/dtutils.lua b/lib/dtutils.lua index ee9f4ee..1798163 100644 --- a/lib/dtutils.lua +++ b/lib/dtutils.lua @@ -65,7 +65,7 @@ function dtutils.check_min_api_version(min_api, script_name) dt.print_error("This application is written for lua api version " .. min_api .. " or later.") dt.print_error("The current lua api version is " .. current_api) dt.print("ERROR: " .. script_name .. " failed to load. Lua API version " .. min_api .. " or later required.") - dt.control.sleep(2000) -- aqllow time for the error to display before script_manager writes it's error message + dt.control.sleep(2000) -- allow time for the error to display before script_manager writes it's error message error("Minimum API " .. min_api .. " not met for " .. script_name .. ".", 0) end end @@ -101,8 +101,8 @@ function dtutils.check_max_api_version(max_api, script_name) dt.print_error("This application is written for lua api version " .. max_api .. " or earlier.") dt.print_error("The current lua api version is " .. current_api) dt.print("ERROR: " .. script_name .. " failed to load. Lua API version " .. max_api .. " or earlier required.") - dt.control.sleep(2000) -- aqllow time for the error to display before script_manager writes it's error message - error("Mzximum API " .. max_api .. " not met for " .. script_name .. ".", 0) + dt.control.sleep(2000) -- allow time for the error to display before script_manager writes it's error message + error("Maximum API " .. max_api .. " not met for " .. script_name .. ".", 0) end end From 1792410efe1ffdf2c6300a7c80120fa065783050 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sat, 15 Jul 2023 19:52:39 -0400 Subject: [PATCH 4/4] lib/dtutils.lua - corrected test --- lib/dtutils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dtutils.lua b/lib/dtutils.lua index 1798163..ad8abfa 100644 --- a/lib/dtutils.lua +++ b/lib/dtutils.lua @@ -97,7 +97,7 @@ dtutils.libdoc.functions["check_max_api_version"] = { function dtutils.check_max_api_version(max_api, script_name) local current_api = dt.configuration.api_version_string - if max_api < current_api then + if current_api > max_api then dt.print_error("This application is written for lua api version " .. max_api .. " or earlier.") dt.print_error("The current lua api version is " .. current_api) dt.print("ERROR: " .. script_name .. " failed to load. Lua API version " .. max_api .. " or earlier required.")