• Advertisement
Sign in to follow this  

Chaining methods for host api objects.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement