Jump to content
  • Advertisement
Sign in to follow this  
Alexander Orefkov

Chaining methods for host api objects.

This topic is 494 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

In my host app I have simple ostream'like object with metods, returning reference for self, for chaining methods.

For example

class MyBuffer {
	MyBuffer& operator<<(const string& s) {
		...
		return *this;
	}
	MyBuffer& operator<<(int i) {
		...
		return *this;
	}
};

I register it as RegisterObjectMethod("MyBuffer", "MyBuffer& opShl(const string&in)"....

and so on.

Another object has member with type MyBuffer.

For example,

class Responce {
  ....
    MyBuffer body;
  ....

In script I write function which I call from app:

void handler(Responce@ res) {
   res.body << "Hello " << 1 << " world!"
}

But even in for first call for string "Hello" - AngelScript attemp create temp copy of MyBuffer and call method of temp var instead of real object.

asEP_ALLOW_UNSAFE_REFERENCES is on.

How I can implement chainig of methods call?

Share this post


Link to post
Share on other sites
Advertisement

The MyBuffer type has to be registered as a reference type to avoid the temporary copy of the object. Or else, you could make the MyBuffer share the internal buffer and only do a shallow copy.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!