Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

- - - - -

Error when sharing script defined enum across many modules


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Hardguy   Members   -  Reputation: 241

Like
0Likes
Like

Posted 04 January 2012 - 03:15 AM

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?


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 2348

Like
0Likes
Like

Posted 04 January 2012 - 03:10 PM

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

#3 Hardguy   Members   -  Reputation: 241

Like
0Likes
Like

Posted 10 January 2012 - 10:48 AM

(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?


#4 Andreas Jonsson   Moderators   -  Reputation: 2348

Like
0Likes
Like

Posted 10 January 2012 - 11:54 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS