Advertisement

Error when sharing script defined enum across many modules

Started by January 04, 2012 09:15 AM
2 comments, last by WitchLord 12 years, 10 months ago
I have gotten a exception when using an enum across several modules.

Here is the setup (in simplified form):

interface.code:

enum eMyEnum
{
eFirst,
//....
}

interface iMyInterface
{
void SomeKindOfAction(eMyEnum aData);
}


implemented.code:
#include "interface.code"
class cMyClass : iMyInterface
{
void SomeKindOfAction(eMyEnum aData)
{
///...
}
}


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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
(Late answer, got no e-mail notification that I got a reply...must check settings)

So what I do is simply:

shared class cMyClass {}

and

shared interface cMyClass {}

for anything that will be used by several modules?
Yes, when the shared entity has already been built in another module the compiler will automatically recognize that and use the previously built code.

Here's the manual entry:

http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_shared.html

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement