🎉 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!

wacky behaviour when using out references (2.6.0 WIP 3)

Started by
12 comments, last by WitchLord 18 years, 3 months ago
i see that. is easy if i use a lot of functions that use const String& in passed as parameters, but if i have functions that returns object on the stack, without returning references nor pointers, i have to manually rewrite it. as the RegularExpression function that were running me on troubles, making it returns a newly created asString object instead of just returning the object on the stack. for example i registered functions to work with URLs, that have a function like

class URL {
public:
// ...
const String getContentAsString();
};

or just my String

String substring( int start, int end );

so i should manage this type of functions to be returning a asString* instead, so i have to write wrapper classes for this type of functions, and that's the 80% of the total number of them, cause i don't work too much with pointers in such cases (safer). there is any workaround ?

Advertisement
Unfortunately there are no other solutions to this than to write wrapper functions. At least no solution that I can think of at the moment.

AngelScript is expecting you to return an asString object, therefore the application registered function must return an asString object. If it returns a String object instead you're going to run into problems as the two objects are not 100% compatible.

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

ok lord, but what if i register String instead of asString ? then returning a String on the stack is working or i should have declared it returning a newly allocated object ?
If you register the String class as-is, without the wrapper class, then you can also register application functions that return String objects by value.

But, because the String class doesn't have support for object handles, you'll find that AngelScript does a lot of copying of the string objects, which may or may not make a difference to you.

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