🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Chaining methods for host api objects.

Started by
0 comments, last by WitchLord 7 years, 1 month 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?

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.

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