Skip to content

Commit 40c8d93

Browse files
committed
Only define instance constants if struct name is non-local
This allows defining structs whose name contains a dot.
1 parent 7e1ffe1 commit 40c8d93

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Of particular interest is `DEF STRUCT_SEPARATOR equs "."`, which causes members
151151

152152
It is unnecessary to put a label right before `dstruct`, since a label is declared at the struct's root.
153153

154-
Two extra constants are declared, that mirror the struct's: `sizeof_Player` would be equal to `sizeof_NPC`, and `Player_nb_fields` would equal `NPC_nb_fields` (sse below).
154+
Unless the struct's name contains a dot `.`, two extra constants are declared, that mirror the struct's: `sizeof_Player` would be equal to `sizeof_NPC`, and `Player_nb_fields` would equal `NPC_nb_fields` (sse below).
155155
These constants will keep their values even if the originals, such as `sizeof_NPC`, are `PURGE`'d.
156156
Like structs' constants, these are not exported unless `STRUCTS_EXPORT_CONSTANTS` is defined.
157157

structs.inc

+7-5
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,14 @@ MACRO dstruct ; struct_type, instance_name[, ...]
308308
PURGE FIELD_ID, ARG_NUM, DSTRUCT_SEPARATOR
309309
310310
; Define instance's properties from struct's
311-
DEF \2_nb_fields EQU \1_nb_fields
312-
DEF sizeof_\2 EQU @ - (\2)
313-
structs_assert sizeof_\1 == sizeof_\2
311+
IF !STRIN("\2", ".")
312+
DEF \2_nb_fields EQU \1_nb_fields
313+
DEF sizeof_\2 EQU @ - (\2)
314+
structs_assert sizeof_\1 == sizeof_\2
314315
315-
IF DEF(STRUCTS_EXPORT_CONSTANTS)
316-
EXPORT \2_nb_fields, sizeof_\2
316+
IF DEF(STRUCTS_EXPORT_CONSTANTS)
317+
EXPORT \2_nb_fields, sizeof_\2
318+
ENDC
317319
ENDC
318320
319321
PURGE IS_NAMED_INSTANTIATION

0 commit comments

Comments
 (0)