Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Cast Handle to reference (like parameter reference)


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
1 reply to this topic

#1 iraxef   Members   -  Reputation: 301

Like
0Likes
Like

Posted 06 December 2013 - 09:56 PM

(I've read this post about "pointers, references and values between C++ and AngelScript" http://www.gamedev.net/topic/608659-pointers-references-values-between-c-and-angelscript/ .. I'm not quite finding the answer to my question)

 

Let's say I've register a reference type TypeA (which the script cannot create, only operate on existing instances) and a TypeB.

RegisterObjectType("TypeA", 0, asOBJ_REF | asOBJ_NOCOUNT);
RegisterObjectType("TypeB", 0, asOBJ_REF | asOBJ_NOCOUNT);

...

RegisterObjectMethod("TypeA", "const TypeB& GetSomeComponent() const", asMETHODPR(TypeA, GetSomeComponent, (void) const, const TypeB&), asCALL_THISCALL);

In script I'm trying to do something like:

void main(TypeA& a)
{
  const TypeB& b = a.GetSomeComponent();
  ...

This fails to compile the script  (with the error "Expected expression value").

 

If I change to the following, it compiles and runs:

// in C++
RegisterObjectMethod("TypeA", "const TypeB@ GetSomeComponent() const", asMETHODPR(TypeA, GetSomeComponent, (void) const, const TypeB&), asCALL_THISCALL);

// in script
const TypeB@ b = b.GetSomeComponent();

Questions:

  • Is it OK to bind to a C++ function that's returning a reference (not a pointer) and feed that to AngelScript as a Handle?
  • I'm guessing that the reference syntax is only available to function parameters? Is there no way to use it in the script body, even if I can guarantee that this object will never be NULL (so I don't want 'pointer'/handle syntax, which would imply that it could be NULL.. there's a reason I'm returning a reference and not a pointer in C++).

 

Thank you very much for your time and tips.


Edited by iraxef, 06 December 2013 - 10:00 PM.


Sponsor:

#2 ThyReaper   Members   -  Reputation: 459

Like
0Likes
Like

Posted 07 December 2013 - 02:20 AM

The C++ side can return a reference or a handle in that case. However, as you suspected, scripts can only use reference syntax in arguments. In your examples, both scripts would receive the return as a const TypeB@.


Edited by ThyReaper, 07 December 2013 - 02:20 AM.





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