]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/self.qh
Propagate this
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / self.qh
1 #pragma once
2
3 // Transition from global 'self' to local 'this'
4
5 [[alias("self")]] entity __self;
6
7 // Step 1: auto oldself
8 #if 1
9 #if NDEBUG
10         #define SELFPARAM() noref entity this = __self
11         #define setself(s) (__self = s)
12         #define self __self
13 #else
14     noref string self_str;
15         #define SELFPARAM() self_str = "self"; noref entity this = __self
16         #define setself(s) (self_str = #s, __self = s)
17         #define self (print(__SOURCELOC__, ": ", self_str, "\n"), __self)
18 #endif
19 #endif
20
21 // Step 2: check SELFPARAM() is present for functions that use self
22 #if 0
23         #define SELFPARAM() [[alias("__self")]] noref entity this = __self
24         #define setself(s) (__self = s)
25         #define self this
26 #endif
27
28 // Step 3: const self
29 #if 0
30         #define SELFPARAM() noref const entity this = __self
31         entity setself(entity e) { return self = e; }
32         entity getself() { return self; }
33         #define self getself()
34 #endif
35
36 // Step 4: enable when possible
37 // TODO: Remove SELFPARAM in favor of a parameter
38 #if 0
39         #define SELFPARAM() noref const entity this = __self
40         #define self this
41 #endif