Advertisement

Chaining methods for host api objects.

Started by May 16, 2017 04:24 AM
0 comments, last by WitchLord 7 years, 6 months ago

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?

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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement