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

Error -10 on register

Started by
3 comments, last by WitchLord 19 years, 2 months ago
Hi What does a -10 error mean when attempting to register a Global function? Here is the code I'm using: //----------------------------------------------------------------------------- // // Register all the functions to make available to the script int scr_RegisterFunctions() //----------------------------------------------------------------------------- { int r = 0; if (NULL == scriptEngine) { conPrint (GL_TRUE, "Failed to register functions. ScriptEngine is not ready."); return -1; } r = scriptEngine->RegisterGlobalFunction("void scr_Output(string ∈)", asFUNCTION(scr_Output), asCALL_CDECL); if (r < 0) { conPrint (GL_TRUE, "Failed to registerGlobalFunction. Error [ %i ]", r); return -1; } Here is the function I'm attempting to register; //----------------------------------------------------------------------------- // // Print to console from script file void scr_Output(std::string &scriptString) //----------------------------------------------------------------------------- { conPrint (GL_FALSE, "[ %s ]", scriptString.c_str()); } and here is the script: // // Test Angelscript to see how we go void testScriptPrint() { int a = 0; int b = 0; scr_Output("Test from within script and edited while running."); scr_Output("Here is a second line as well."); } and this is my logfile output: 00:44:33 > Script version [ 1.10.1d ] 00:44:33 > ScriptEngine created... 00:44:33 > Size of script [ 1553 ] 00:44:33 > Failed to registerGlobalFunction. Error [ -10 ] Thanks
Advertisement
Did you register std::string?

Um - no

How do I do that?
You can register std::string and other object types using the following asIScriptEngine methods:

RegisterObjectType(...)
RegisterObjectProperty(...)
RegisterObjectMethod(...)
RegisterObjectBehaviour(...)

I believe there is specific sample code for registering std::string as part of the AngelScript distro.

In general, you can only register a global variable if the type of that variable is one of the supported native types or if it is a class / struct registered with AngelScript using the above methods. The same applies for global functions and object methods - all parameters and the return type must be an AS native type or a registered type. In short, registration order is important.

So basically you need to register all your stuff starting from the simplest elements first, typically simple functions and classes that only only have native types in their signatures, followed by the more complex functions and classes that refer to the simple classes, and so on and so forth. I find it good practice to register global variables last.

I suggest you have a look at the Overview of AngelScript article on the AngelCode website and for a detailed reference, take a look at Application Writer's manual and Script Writer's manual.
tIDE Tile Map Editorhttp://tide.codeplex.com
Thanks Rain Dog and SharkBait for helping out. :)

Gibbon_99:

-10 means asINVALID_DECLARATION. This information is available in the angelscript.h file, just search for "Return codes". In your case it would mean that AngelScript doesn't understand the 'string' type that you are using for the parameter.

AngelScript doesn't have a native string type, but instead allows the application to register it's own string type with the proper behaviour and methods to be compatible with the application's other functions. I have written a special string class, called asCScriptString, that is available in the zip file you downloaded for AngelScript (you'll find it in the add_on folder).

asCScriptString is compatible with std::string, in that it can be sent as reference to a function that expects a std::string by reference. In addition to the normal std::string class, it also adds reference counting which means that it is compatible with AngelScript's object handles. Registering this string type is as simple as calling RegisterScriptString(), which is declared in scriptstring.h.

I suggest you take a look at the sample application (available in the samples/console folder), for more information on how to register types and functions with the library. You may also download the Texture Generator source code from my site.

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

This topic is closed to new replies.

Advertisement