mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-09 20:47:00 -04:00
add "version_is_older" script function
This commit is contained in:
@@ -138,5 +138,6 @@ These functions are built into the program, other [[type:function]]s can be defi
|
||||
| [[fun:assert]] Check a condition for debugging purposes.
|
||||
| [[fun:warning]] Output a warning message.
|
||||
| [[fun:error]] Output an error message.
|
||||
| [[fun:version_is_older]] Checks if a version number is older than another.
|
||||
| [[fun:exists_as_package]] Checks if a package exists.
|
||||
| [[fun:exists_in_package]] Checks if a file exists in a package.
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
Function: version_is_older
|
||||
|
||||
--Usage--
|
||||
> version_is_older("version", than: "other version")
|
||||
|
||||
Check if a version number is strictly older than another.
|
||||
|
||||
Malformed version numbers, including nil, are treated as 0-0-0.
|
||||
|
||||
--Parameters--
|
||||
! Parameter Type Description
|
||||
| @input@ [[type:string]] Version we want to check.
|
||||
| @than@ [[type:string]] Version we want to check against.
|
||||
|
||||
--Examples--
|
||||
> version_is_older("2025-06-28", than: "2026-02-18") == true
|
||||
> version_is_older("2026-02-18", than: "2026-02-18") == false
|
||||
> version_is_older(nil, than: "0-0-1") == true
|
||||
@@ -90,6 +90,14 @@ SCRIPT_FUNCTION(error) {
|
||||
return script_nil;
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(version_is_older) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
SCRIPT_PARAM(String, than);
|
||||
Version input_version = Version::fromString(input);
|
||||
Version than_version = Version::fromString(than);
|
||||
SCRIPT_RETURN(input_version < than_version);
|
||||
}
|
||||
|
||||
SCRIPT_FUNCTION(exists_as_package) {
|
||||
SCRIPT_PARAM_C(String, input);
|
||||
Version version_out;
|
||||
@@ -1026,6 +1034,7 @@ void init_script_basic_functions(Context& ctx) {
|
||||
ctx.setVariable(_("trace"), script_trace);
|
||||
ctx.setVariable(_("warning"), script_warning);
|
||||
ctx.setVariable(_("error"), script_error);
|
||||
ctx.setVariable(_("version_is_older"), script_version_is_older);
|
||||
ctx.setVariable(_("exists_as_package"), script_exists_as_package);
|
||||
ctx.setVariable(_("exists_in_package"), script_exists_in_package);
|
||||
// conversion
|
||||
|
||||
Reference in New Issue
Block a user