Skip to content

Commit 33534a8

Browse files
authored
Merge pull request #538 from memo33/dll-semversion
parse semantic DLL version in Advisor Lua script
2 parents 22654ce + 772a288 commit 33534a8

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

lua/adv_nam_dll.lua

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@
33
-- This file defines advisor messages related to the NAM DLL.
44

55
-- Note that this Lua file is not intended for distribution with the DLL itself, but for distribution with the NAM DBPF files to ensure compatibility between NAM and DLL.
6-
nam_dll_version_expected = "1.2.0" -- needs to be updated whenever a new DLL version is released
6+
nam_dll_version_expected = "1.3.0" -- needs to be updated whenever a new DLL version is released
77

8-
-- (When this script is first executed, the `nam_dll_version` is still `nil`, but it gets defined before the trigger conditions are evaluated.)
8+
local _cached_result = nil
99
function is_nam_dll_correct()
10+
-- (When this script is first executed, the `nam_dll_version` is still `nil`, but it gets defined before the trigger conditions are evaluated.)
1011
local version = rawget(globals(), "nam_dll_version")
11-
return version ~= nil and version == nam_dll_version_expected
12+
if (version == nil) then
13+
return false
14+
elseif (_cached_result ~= nil) then
15+
return _cached_result
16+
else
17+
if (version == nam_dll_version_expected) then
18+
_cached_result = true
19+
else
20+
-- check semantic versions to allow a patch level higher than expected by this Lua script
21+
local semver_pattern = "^(%d+%.%d+)%.(%d+)"
22+
local i, _, v12, v3 = string.find(version, semver_pattern)
23+
local j, _, e12, e3 = string.find(nam_dll_version_expected, semver_pattern)
24+
if (i == nil or j == nil) then
25+
_cached_result = false
26+
else
27+
_cached_result = (v12 == e12 and tonumber(v3) >= tonumber(e3))
28+
end
29+
end
30+
return _cached_result
31+
end
1232
end
1333

1434
------------ Advice record ----

0 commit comments

Comments
 (0)