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

Disadvantages of generic..?

Started by
6 comments, last by 39ster 16 years, 4 months ago
In the string class addon you have generic functions/operators and native functions/operators. Why do you have both? Why not just generic?
Advertisement
The generic calling method is the only one available when AS_MAX_PORTABILITY is defined. In order to support this directive generic methods need to be implemented along side their normal counterparts.
The generic functions have a bit more overhead than the native functions, since they normally wrap the native functions in order to transport the data between AngelScript and the application.

For the add-ons I implement both, to allow speed where native functions are supported, yet maintain portability where they are not.

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. How come native calling isnt supported sometimes? Will it not work on all compilers?
Native calling conventions differs depending on three factors: target CPU, target OS, and compiler used. AngelScript uses customized assembly code for each combination that is supported.

AngelScript does support native calling conventions on most of the major platforms, but there are still some platforms that only work with the generic calling convention (which is pure C++, thus works everywhere).

List of supported platforms

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 one last question. From a native function, how do i return an object? For example "string toLower(string& in)". In generic you do something like this:

*(asCScriptString**)gen->GetReturnPointer() = new asCScriptString()
how do i do it in native?
Since you're using asCScriptString you cannot return the object by value in native mode (since that requires the object to be placed on the stack, which is not compatible with reference counting). Instead you should return the object with an object handle:

// Registered as "string @toLower(string ∈)"asCScriptString *toLower(std::string &s){  // Return the new string in an object handle  return new asCScriptString();} 

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 thankyou. Now i realise why i was getting a memory leak before. I defined it like

string& toLower(string ∈)
i used the wrong symbol. Should of used "@".

This topic is closed to new replies.

Advertisement