Global Constants
MiranDMC opened this issue · 4 comments
I have some thoughts about constants. It is bit problematic that constants are valid only in code after they were declared. In bigger projects with includes it is getting very difficult as at certain point it is even impossible to manage correct include order to make sure constants can be used everywhere.
I mean there are some cases where defined constants should be available globally in same way labels are:
const
Stuff_Red = 0
Stuff_Green = 1
Stuff_Blue = 2
end
// arg 0 - stuff value
:FUNC_SET_STUFF
// DO SOMETHING WITH STUFF
cleo_return
In this example function FUNC_SET_STUFF
will be available globally but depending on includes order calling cleo_call @FUNC_SET_STUFF args 1 Stuff_Blue
will cause argument of function to be actually default 0, as constant Stuff_Blue
will be unknown.
Modifying behaviour of existing constants might probably not be wise idea, so how about add extra keyword to declaration like global const
?
Use $INCLUDE_ONCE to add the same constants in any scope and avoid compiler error on duplicate name.
the only problem is that language service does not know about INCLUDE_ONCE and you won't get constants in auto-complete.
I fixed it, try this
core.zip
I noticed the problem with language service too.
Include_Once won't help in case of circular references, as one of two will be always included first. It leads to need of spiting code into header and source files. This makes code in example less readable as scm
- is not hard typed, so function return type is not obvious
- there is no 'go to definition' feature, so if constant pretending to be enum is not on same screen it is not helpful
Can you provide a complete project with includes so I can see it for myself?
Header with constant definitions offers walk-around.