For example it should be allowed to store the OP in a local variable, but not a global variable, it must not be possible to store the OP in a class member, unless the class itself is guaranteed to die after the function returns. I'm not sure how you expect AngelScript to control this.
A class with an OP shouldn't be stored globally. To make it easier I wouldn't mind simply disallowing all global variables (it's good design anyway) I think I can easily patch this in myself with the following code (in as_compiler.cpp, after line 6269):
if( found ){
Error( "ERROR: NO GLOBAL VARIABLES ALLOWED!", errNode );
return -1;
}
All state data between calls will then be stored outside of AS.
This means that I'll be running a modified version of AS. I think making a better solution will require quite some work (disallowing classes with OPs to be stored in global variables) on your end and I don't want to deliver you any more work than necessary.
Unfortunately, I'm still not sure how disallow the following AS code (any pointers willbe greatly appreciated):
void main() {
SomeData some_data;
some_function( some_data );
}
While still allowing:
void main() {
SomeData some_data = some_other_function();
}
The "IsVariableInitialized" returned always "true" for the code I tested it with. I placed the following code right at the beginning/end of "asCCompiler::CompileVariableAccess" hoping that it would return false for the first case of "SomeData".
cout << " IsVariableInitialized" << name.AddressOf() << ", " << IsVariableInitialized( &ctx->type, errNode ) << endl;
Alternatively you can implement a proxy class [..]
This is an interesting alternative, I'll consider it. I'm not a big fan of runtime errors when they can be found at compile time. There is also a (small?) amount of additional overhead/complexity.