NorthstarLauncher icon indicating copy to clipboard operation
NorthstarLauncher copied to clipboard

Use Semver in Dependency Constants

Open uniboi opened this issue 2 years ago • 17 comments

If a mod for a dependency constant is loaded, this will create a sqvm constant that's a SQTable holding the dependency's major, minor and patch version as integer. All other subversions are omitted. If a dependency is not loaded, the constant will be 0 instead.

This does not break compatability with old versions since a table is a truthy value like 1, as it is now.

This allows modders to compile code for ranges of mod versions.

For example:

#if HAS_UEBERBLICK
// This compiles only if the dependency is loaded. No matter the version of the dependency
#endif

#if HAS_UEBERBLICK && HAS_UEBERBLICK.major == 1
// This compiles ONLY if the dependency version is 1.x.x
#endif

#if HAS_UEBEBLICK && HAS_UEBERBLICK.major == 1 && HAS_UEBERBLICK.minor >= 2 && HAS_UEBERBLICK.minor <= 5
// This compiles only if the dependency's version is between 1.2.x - 1.5.x
#endif

Invalid version numbers are represented as -1.

  • "1.2.test" major: 1 minor: 2 patch: -1

  • "1." major: 1 minor: -1 patch: -1

  • "heheheha" major: -1 minor: -1 patch: -1

etc.

uniboi avatar Feb 15 '23 10:02 uniboi

I assume v1.12.1-rc would then be:

major: 1 minor: 12 patch: 1

?

GeckoEidechse avatar Feb 19 '23 01:02 GeckoEidechse

v1.12.1-rc would be

mj: -1 mn: 12 pt: -1

since I did not bother writing an semver parser because a) I have never seen a mod with a leading v in the version b) I don't think anyone is playing on release candidates

uniboi avatar Feb 19 '23 12:02 uniboi

v1.12.1-rc would be

mj: -1 mn: 12 pt: -1

since I did not bother writing an semver parser because a) I have never seen a mod with a leading v in the version

the leading v was a force of habit, forgot that it's not in the mods version

b) I don't think anyone is playing on release candidates

sadly cause we really need more playtesters x_x

GeckoEidechse avatar Feb 19 '23 16:02 GeckoEidechse

I could just terminate on a -, I guess. parsing rc subversion doesn't make sense imo

uniboi avatar Feb 19 '23 16:02 uniboi

I could just terminate on a -, I guess. parsing rc subversion doesn't make sense imo

Yeah that's fine. Was just wondering whether it would be a -1 or whether the -rcX is stripped and turned into just the 1 for patch ^^

GeckoEidechse avatar Feb 19 '23 16:02 GeckoEidechse

Ignores now anything after a -

uniboi avatar Feb 21 '23 17:02 uniboi

genuinely surprised any kind of table stuff works in #ifs?

BobTheBob9 avatar Feb 22 '23 22:02 BobTheBob9

Conditions for #if are normal squirrel expressions, they just need to be able to be evaluated at compile time (ie be constant).

Even stuff like this works #if { k = 1 }.k == int(CLIENT), even if unnecessary

uniboi avatar Feb 23 '23 06:02 uniboi

fuck

uniboi avatar Feb 23 '23 18:02 uniboi

This is broken atm actually idk what I did

uniboi avatar Mar 11 '23 00:03 uniboi

fixed again. dep_test.zip To test: Install both mods in the zip. In the mp lobby, the globals a = 1, b = 2 and c = 3 should be defined while d = 4 isn't.

uniboi avatar Mar 11 '23 00:03 uniboi

Small request:

Make the version available as a string as well :)

EladNLG avatar Mar 12 '23 00:03 EladNLG

Make the version available as a string as well :)

you can now do checks like #if CONSTANT.version == "1.2.3" #elseif CONSTANT.version == "1.2.3-rc1" #endif

uniboi avatar Mar 12 '23 13:03 uniboi

It looks like the game crashes when accessing a dependency constant table and then recompiling scripts

uniboi avatar Mar 26 '23 15:03 uniboi

@uniboi is this still going to be worked on? Or has the crashing discouraged you?

ASpoonPlaysGames avatar Aug 25 '23 16:08 ASpoonPlaysGames

I think it might just be a refcount issue, I haven't tested any further though. Might try soon:tm:

uniboi avatar Aug 26 '23 21:08 uniboi

@uniboi heads-up that there are merge conflicts here ^^

GeckoEidechse avatar Nov 21 '23 01:11 GeckoEidechse

fixed in #685

uniboi avatar Apr 01 '24 22:04 uniboi