Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

Question about value types


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
4 replies to this topic

#1 Grimshaw   Members   -  Reputation: 654

Like
0Likes
Like

Posted 31 March 2013 - 03:16 PM

I have a doubt about angelscript that I need to clarify.

 

For lightweight classes which are efficiently passed by value, is there a way to still store handles to the object?

 

Explaining with an example: I have a Sprite class which is quite simple, having only a few members. I registered this as a Ref type because i wanted to pass it around through functions, modifying the original instance.

 

However, such a lightweight class could fit well as a value type , I believe... But if I do that, I am not sure I can still pass a sprite to a function(in-script) and modify the original Sprite object rather than its copy. Or can I?

 

Thanks in advance.


Indie Game Developer - Daeva Theory Studios

 

Twitter - Facebook

 

Next

Terra - rise of mankind

 

Previous

SFML Game Development (Book)


Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9668

Like
0Likes
Like

Posted 31 March 2013 - 03:20 PM

You can pass a reference to the object. Ex: void foo(MyObject & inout).

#3 Grimshaw   Members   -  Reputation: 654

Like
0Likes
Like

Posted 31 March 2013 - 08:57 PM

I mean inside the scripts.. Not from / to C++.

 

Sprite s;

 

changeThisSprite(@s); // or something similar


Indie Game Developer - Daeva Theory Studios

 

Twitter - Facebook

 

Next

Terra - rise of mankind

 

Previous

SFML Game Development (Book)


#4 Jake Albano   Members   -  Reputation: 649

Like
0Likes
Like

Posted 01 April 2013 - 09:13 AM

You can only use object handles with reference types, but inout references will work with value types if you allow the script engine to use unsafe references.

engine->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, true);

 

You can then use them inside scripts as well as passing tom C++.

void modify(Sprite & inout s)
{
    // modify the sprite
}

 

Be aware that you are now responsible for ensuring that parameters passed as inout remain valid for as long as they're in use. The script engine can't guarantee their lifetime, so it's possible to crash your application by passing temporary values into C++.


Edited by Jake Albano, 01 April 2013 - 09:13 AM.


#5 Grimshaw   Members   -  Reputation: 654

Like
0Likes
Like

Posted 01 April 2013 - 04:00 PM

Thanks for the answer Jake! It clarifies things!


Indie Game Developer - Daeva Theory Studios

 

Twitter - Facebook

 

Next

Terra - rise of mankind

 

Previous

SFML Game Development (Book)





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