Registering a static method as a object method

Started by
2 comments, last by Jackozzo 2 years ago

I'd like to extend array add-on class by adding a T& RandomElement() method to the class. I could easily modify CScriptArray class interface but it would be easier to add a free method like template<typename T> T& randomElement(CScriptArray*) instance so that I can extend the behavior without modifying the underlying structure.

Is this possible?

Advertisement

Yes, you can easily do this. Implement the new array method as a global function (or static class method) in C++ and register it with RegisterObjectMethod using the calling convention asCALL_CDECL_OBJLAST (or asCALL_CDECL_OBJFIRST, depending on where you want the array pointer to be sent).

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

Thank you for your answer, I think I found where this is explained in the manual by searching for your specified call convention, sorry if the question was trivial ?

I like how AngelScript is implemented, a lot of choices that I would have made exactly the same, I actually had my own scripting language since this is for a big project I preferred to go with something very mature like your implementation. I'm actually curious about an implementation detail but I'll use a different thread.

This topic is closed to new replies.

Advertisement