main.code: #include "interface.code"
void DoSomething()
{
//GetMyClass is implemented in C++ and returns cMyClass as implemented in "implemented.code"
iMyInterface @pData = GetMyClass();
pData.SomeKindOfAction(eFirst);
}
One module is built from "implemented.code" and one from "main.code".
When running DoSomething() the script returns that an exception has occured when calling the line:
pData.SomeKindOfAction(eFirst);
If I change to eMyEnum to int all works fine and there is no exception.
Am I doing something wrong here or might this be a bug, or just a limitation of the script?
Bonus questions:
1) If this is an error, does this apply to classes aswell? (Do I need to use interfaces as params?)
2) If enums cannot be shared across modules, is it possible to do: int x=0;
eMyEnum e = x;
Some how?
Right now the enum types are not shared between modules. Because the enum type is not shared the interface that use the enum in one of its parameters also isn't shared.
Unfortunately with the automatic detection of identical interfaces this is a silent error which is only discovered when you try to cast a handle to the interface you thought was shared but really isn't. This is one of the reasons I introduced the 'shared' keyword. When declaring the interface with the shared keyword, the compiler will not allow the use of any non-shared types.
Classes can be shared if declared with the 'shared' keyword.
I plan on implementing support for shared enums as well, but this is not yet implemented.
An integer can be assigned to an enum with an explicit cast.
eMyEnum e = eMyEnum(x);
Observe that just as in C++ there is no validation to guarantee that the number actually represents one of the defined enum values.