-
Notifications
You must be signed in to change notification settings - Fork 0
Conditional compiling
Jeroen Broks edited this page Aug 14, 2020
·
1 revision
Neil has support for conditional compiling
#undef str
#if str
String MyVar
#else
Int MyVar
#fi
Init
for i=1,10
MyVar += 1
end
print(MyVar)
End
The script above was written to test this.... The output will be "10"... Now replace the "#undef str" line with "#define str" and the output will be "1111111111". This because MyVar has suddenly become a string and += will then go concatenating in stead of increasing as it would do with an integer value.
- Other compiler directives will still work, even if the "#if" clause should normally not allow you to.. This was a bit of an issue of the lexing and parsing stages a Neil script goes through in the translation process. Although it is possible this may be solved in the future somehow... Everything else will just be ignored if an "#if" clause obligates Neil to.
- Conditional compiling is always playing with power. Please note that scopes can be messed up with this, as #if doesn't take it into account (like it shouldn't).
- Conditions prefixed with "LOC_" will only be taken into account in the script in which they were set. All other conditions are global and will affect all translations within the Lua state.
- Conditions prefixed with "SYS_" are reserved for system settings. You can check them with "#if" (and "#elseif"), but you cannot modify their settings with "#define" and "#undef"
- Conditions are case insensitive, like nearly everything else in Neil.
- You can check multiple conditions with #if and #elseif, but they will all be checked in an "and" comparing. "#if one two three" can therefore be seen as "if one and two and three"... Other kinds of comparing are not yet possible.
- "#fi" and "#endif" have the same effect. And so "#elif" and "#elseif" are also aliases for each other.
- I must note.... whenever #if turns out false, all code until #else, #endif, #elseif is simply ignored by Neil and will not be translated at all, so the Lua compiler will never get to see that code. The chopper-stage (which is where the lexer sorts out what kind of word is what, so the translator can process it all more easily) does not ignore the code, meaning some errors caused in this stage (like unfinished strings) will still be thrown and stop the translation process (and deem it failed).
- Unlike C, the definitions are not marcos in Neil. In Neil macros are handled separately.