Skip to content

Commit f99fff1

Browse files
committed
Add version checking macro
1 parent 9043b99 commit f99fff1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

structs.asm

+45
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,51 @@
2323
; SOFTWARE.
2424

2525

26+
; Yes I need this macro, for version checking.
27+
; What did you expect from a macro pack that mostly relies on code generation at compile time?
28+
; Also this is your last chance to turn back. It doesn't get any better.
29+
30+
; strreplace variable_name, original_char, new_char
31+
strreplace: MACRO
32+
DOT_POS = STRIN("{\1}", \2)
33+
IF DOT_POS != 0
34+
TMP equs STRCAT(STRSUB("{\1}", 1, DOT_POS + (-1)), STRCAT(\3, STRSUB("{\1}", DOT_POS + 1, STRLEN("{\1}") - DOT_POS)))
35+
PURGE \1
36+
\1 equs "{TMP}"
37+
PURGE TMP
38+
strreplace \1, \2, \3
39+
ENDC
40+
IF DEF(DOT_POS)
41+
PURGE DOT_POS
42+
ENDC
43+
ENDM
44+
45+
46+
; rgbds_structs_version version_string
47+
; Call with the expected version string to ensure you're using a compatible version
48+
; Example: rgbds_structs_version 1.0.0
49+
rgbds_structs_version: MACRO
50+
CURRENT_VERSION equs "1,1,0"
51+
EXPECTED_VERSION equs "\1"
52+
strreplace EXPECTED_VERSION, ".", "\,"
53+
check_ver: MACRO
54+
IF \1 != \4 || \2 > \5 || \3 > \6
55+
PURGE EXPECTED_VERSION
56+
ENDC
57+
ENDM
58+
CHECK_VER_CALL equs "check_ver {EXPECTED_VERSION},{CURRENT_VERSION}"
59+
CHECK_VER_CALL
60+
IF !DEF(EXPECTED_VERSION)
61+
strreplace CURRENT_VERSION, "\,", "."
62+
FAIL "RGBDS-structs version \1 is required, which is incompatible with current version {CURRENT_VERSION}"
63+
ENDC
64+
PURGE CHECK_VER_CALL
65+
PURGE check_ver
66+
PURGE CURRENT_VERSION
67+
PURGE EXPECTED_VERSION
68+
ENDM
69+
70+
2671
; struct struct_name
2772
; Begins a struct declaration
2873
struct: MACRO

0 commit comments

Comments
 (0)