Jump to content
  • Advertisement
Sign in to follow this  
Hardguy

Error when sharing script defined enum across many modules

This topic is 2530 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
(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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!