Skip to content

Commit 1905be8

Browse files
committed
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.
1 parent 612ecaf commit 1905be8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lib/dtutils.lua

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,42 @@ function dtutils.check_min_api_version(min_api, script_name)
6969
end
7070
end
7171

72+
dtutils.libdoc.functions["check_max_api_version"] = {
73+
Name = [[check_max_api_version]],
74+
Synopsis = [[check the maximum required api version against the current api version]],
75+
Usage = [[local du = require "lib/dtutils"
76+
77+
local result = du.check_max_api_version(max_api, script_name)
78+
max_api - string - the api version that the application was written for (example: "5.0.0")
79+
script_name - string - the name of the script]],
80+
Description = [[check_max_api_version compares the maximum api required for the appllication to
81+
run against the current api version. This function is used when a part of the Lua API that
82+
the script relies on is removed. If the maximum api version is not met, then an
83+
error message is printed saying the script_name failed to load, then an error is thrown causing the
84+
program to stop executing.
85+
86+
Return_Value = [[result - true if the maximum api version is available, false if not.]],
87+
Limitations = [[When using the default handler on a script being executed from the luarc file, the error thrown
88+
will stop the luarc file from executing any remaining statements. This limitation does not apply to script_manger.]],
89+
Example = [[check_max_api_version("9.0.0") does nothing if the api is less than or equal to 9.0.0 otherwise an
90+
error message is printed and an error is thrown stopping execution of the script.]],
91+
See_Also = [[]],
92+
Reference = [[]],
93+
License = [[]],
94+
Copyright = [[]],
95+
}
96+
97+
function dtutils.check_max_api_version(max_api, script_name)
98+
local current_api = dt.configuration.api_version_string
99+
if max_api < current_api then
100+
dt.print_error("This application is written for lua api version " .. max_api .. " or earlier.")
101+
dt.print_error("The current lua api version is " .. current_api)
102+
dt.print("ERROR: " .. script_name .. " failed to load. Lua API version " .. max_api .. " or earlier required.")
103+
dt.control.sleep(2000) -- aqllow time for the error to display before script_manager writes it's error message
104+
error("Mzximum API " .. max_api .. " not met for " .. script_name .. ".", 0)
105+
end
106+
end
107+
72108
dtutils.libdoc.functions["split"] = {
73109
Name = [[split]],
74110
Synopsis = [[split a string on a specified separator]],

0 commit comments

Comments
 (0)