File src/jass_include.m4 added (mode: 100644) (index 0000000..26631cf) |
|
1 |
|
dnl This macro script should be used to arrange arbitrary number of Jass script |
|
2 |
|
dnl snippets into a single file (war3map.j), that will be interpreted by the |
|
3 |
|
dnl game environment at runtime. |
|
4 |
|
dnl |
|
5 |
|
dnl Example usage. |
|
6 |
|
dnl ``` |
|
7 |
|
dnl m4 src/jass_include.m4 src/*.j > war3map.j |
|
8 |
|
dnl pjass etc/common.j Blizzard.j war3map.j |
|
9 |
|
dnl ``` |
|
10 |
|
dnl |
|
11 |
|
dnl Most importantly, this script will ensure that there is only one globals |
|
12 |
|
dnl block. The parsing tool pjass that is used by the community will interpret |
|
13 |
|
dnl multiple globals blocks correctly. The game runtime environment itself will |
|
14 |
|
dnl not. |
|
15 |
|
dnl |
|
16 |
|
dnl Optionally, this script will re-arrange and re-order separate Jass script |
|
17 |
|
dnl snippets, in accordance with their dependencies. For this feature to work, |
|
18 |
|
dnl the snippets themselves must incorporate macros into their source. The |
|
19 |
|
dnl snippet may still be parsed normally with pjass or the game runtime |
|
20 |
|
dnl environment with the macros included. For details, see the definitions of |
|
21 |
|
dnl jass_module and jass_include macros. See src/*.j files in the repository |
|
22 |
|
dnl for example usage of the preprocessor macros in Jass script snippets. |
|
23 |
|
dnl |
|
24 |
|
define(`jass_divert_globals', |
|
25 |
|
`define(`globals', `divert(0)divert(1)')define(`endglobals', `divert(0)divert(2)')dnl' |
|
26 |
|
)dnl |
|
27 |
|
define(`jass_undivert_globals', |
|
28 |
|
`undefine(`globals')undefine(`endglobals')dnl' |
|
29 |
|
)dnl |
|
30 |
|
dnl Divert globals to be re-inserted after all input was processed. |
|
31 |
|
jass_divert_globals()dnl |
|
32 |
|
dnl |
|
33 |
|
dnl jass_module macro should be used in the file that defines the module. |
|
34 |
|
dnl A module is a Jass script snippet in a single file that pjass should parse |
|
35 |
|
dnl successfully. |
|
36 |
|
dnl |
|
37 |
|
dnl When Jass module is declared, check if it was already declared previously. |
|
38 |
|
dnl Given the module was already declared, skip the contents of the file, |
|
39 |
|
dnl and stop diverting globals. |
|
40 |
|
dnl Given the module is yet unknown, then declare the module, |
|
41 |
|
dnl include the content normally, and resume to divert globals. |
|
42 |
|
dnl |
|
43 |
|
dnl (Note, to be frank, I am not entirely sure why toggling globals is needed |
|
44 |
|
dnl here, but it certainly is needed. Probably has something to do with |
|
45 |
|
dnl diversions in the definition of the offending macro.) |
|
46 |
|
dnl |
|
47 |
|
define(`jass_module', |
|
48 |
|
`ifdef(`$1', |
|
49 |
|
`skip `$1' jass_undivert_globals()divert(-1)', |
|
50 |
|
`module `$1' define($1, 1)jass_divert_globals()' |
|
51 |
|
)dnl' |
|
52 |
|
)dnl |
|
53 |
|
dnl |
|
54 |
|
dnl jass_include macro should be used to declare dependency of a module, |
|
55 |
|
dnl on distinct another module. |
|
56 |
|
dnl |
|
57 |
|
dnl When Jass dependency is declared, check if the required module |
|
58 |
|
dnl was already included. |
|
59 |
|
dnl Given the module was already declared as included, |
|
60 |
|
dnl then do nothing. |
|
61 |
|
dnl Given the module was not yet included, |
|
62 |
|
dnl then include it and declare it to be included, |
|
63 |
|
dnl to inform the rest of the script that it mustn't be duplicated. |
|
64 |
|
dnl dnl |
|
65 |
|
define(`jass_include', |
|
66 |
|
`ifdef(`$1', |
|
67 |
|
`requires $2', |
|
68 |
|
`insert `$1' include($2)define(`$1', 1)' |
|
69 |
|
)dnl' |
|
70 |
|
)dnl |
|
71 |
|
dnl |
|
72 |
|
dnl Divert functions to be re-inserted after all input was processed. |
|
73 |
|
divert(2)dnl |
|
74 |
|
dnl |
|
75 |
|
dnl After all input was processed, undivert globals and functions, |
|
76 |
|
dnl to be re-inserted in a valid order. |
|
77 |
|
m4wrap(dnl |
|
78 |
|
`divert(0)undefine(`globals')undefine(`endglobals')dnl |
|
79 |
|
globals |
|
80 |
|
undivert(1)dnl |
|
81 |
|
endglobals |
|
82 |
|
undivert(2)dnl' |
|
83 |
|
)dnl |
File src/war3map.m4 deleted (index 8f35e87..0000000) |
1 |
|
define(globals, `divert(0)divert(1)')dnl # Cut and paste 'globals' blocks |
|
2 |
|
define(endglobals, `divert(0)divert(2)')dnl |
|
3 |
|
divert(2)dnl |
|
4 |
|
dnl # WARNING: included files must never contain the tilde glyph, |
|
5 |
|
dnl # otherwise this m4 script produces malformed *.j snippet |
|
6 |
|
include(`src/spell.j')dnl |
|
7 |
|
include(`src/abla.j')dnl |
|
8 |
|
include(`src/user.j')dnl |
|
9 |
|
include(`src/herotoken.j')dnl |
|
10 |
|
include(`src/altar.j')dnl |
|
11 |
|
include(`src/revive.j')dnl |
|
12 |
|
include(`src/defeat.j')dnl |
|
13 |
|
include(`src/victory.j')dnl |
|
14 |
|
include(`src/main.j')dnl |
|
15 |
|
include(`src/config.j')dnl |
|
16 |
|
divert(0)dnl |
|
17 |
|
undefine(`globals')dnl # Leave 'globals' token as it is |
|
18 |
|
undefine(`endglobals')dnl # Leave 'endglobals' token as it is |
|
19 |
|
|
|
20 |
|
globals |
|
21 |
|
undivert(1) |
|
22 |
|
endglobals |
|
23 |
|
|
|
24 |
|
undivert(2) |
|