Skip to content

Commit 931e7a4

Browse files
authored
Merge pull request darktable-org#416 from wpferguson/check_max_api_version
Add check for max api version
2 parents 8cbd922 + 1792410 commit 931e7a4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

lib/dtutils.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,47 @@ function dtutils.check_min_api_version(min_api, script_name)
6565
dt.print_error("This application is written for lua api version " .. min_api .. " or later.")
6666
dt.print_error("The current lua api version is " .. current_api)
6767
dt.print("ERROR: " .. script_name .. " failed to load. Lua API version " .. min_api .. " or later required.")
68+
dt.control.sleep(2000) -- allow time for the error to display before script_manager writes it's error message
6869
error("Minimum API " .. min_api .. " not met for " .. script_name .. ".", 0)
6970
end
7071
end
7172

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

0 commit comments

Comments
 (0)