Advertisement

AngelScript: Using string instead of string& as parameter?

Started by November 05, 2006 06:24 PM
2 comments, last by WitchLord 18 years ago
Hi, I have a problem. In my engine I use alot of std::string's, and I would love if it was possible to register a function like this: register(function, "void myfunction(string)"); so that I can use functions in my engine such as SetName(std::string name). If do it like that I get this: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. Is there anyway to make this work or do I perhaps need to make my own container class? Now I have to make a special function for each that uses strings like asSetName(string& name) { SetName(name) };
You can register the std::string directly with AngelScript. You'll not be able to use object handles with it though.

Look up the files stdstring.h and stdstring.cpp in the tests/test_feature/source directory for the code.

I do recommend that you change your engine code to use references to std::string however. It is more efficient than copying the string object on to the stack for each call.

Regards,
Andreas

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

Advertisement
Ok thanks. I will probably use refrences later, but as it is now I can do things with the engine in c++ and angelscript. And having multiple functions of the smae thing will just make things more confusing.
I meant for you to replace your current C++ functions that take the string by value, with the new ones that take the string by reference. Not to keep both of them. :)

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