There is one thing I really missing in AngelScript. Constants. I really like constants and have lot of 'em in my code, and it is real pain when I have to copy-paste-adapt them to script files.
So I modified CScriptBuilder addon to enable #define directive and, when I was on it, #ifdef and #ifndef directives as well. This way, I can safely share my .h files between c++ and AngelScript with little compile time overhead and no memory loss.
And I thought I may share it as well - modified CScriptBuilder.c, CScriptBuilder.h and patch against files from Angelscript 2.26.1 SDK.
This patch enables following:
- C-style #define directive, but usable only for constants - no parametric macros
- Anything #defined as 1 or true is stored as "defined word" as well, so standard AngelScript's #if works with it
- C-style #ifdef and #ifndef directives, looking for both "defined words" and macro names
- Ability to negate #if directive with ! character ( #if !LINUX ... #endif )
and it shouldn't break any working code.
Only drawback is that it's using std::map to store macro definitions and that thing is not exactly speed daemon, so having lots of constants may prolong compile time (almost every word in script is compared to every defined macro.) I'm planing to code some more optimized map for this, but I wanted to keep thins simple for start.