Advertisement

Noob question.

Started by February 28, 2021 12:20 PM
3 comments, last by Gnollrunner 3 years, 8 months ago

I'm getting to the point I need scripting for my C++ game/library. Someone on reddit recommended Angelscript to me. I gather it uses reference counting which in general I like. However my game library currently has it's own reference counting/smart-pointer system. So I'm wondering is it possible to easily merge my stuff with Angelscript?

I'm not adverse to making some changes to my code, but it has some specialized heap to heap half sized relative addressing pointers, and object bucketing that I don't want to mess with, so going to a different heap altogether is out of the question. As far as my use of Angelscript will go, I would only need to reference top level objects which use more standard reference counting pointers. These aren't double sized like std::shared_ptr, since my objects have an intrusive reference count.

I'm not looking for detailed instructions on how to do it, just some idea if Angelscript will in general support this kind of thing. Thanks in advance.

Gnollrunner said:
However my game library currently has it's own reference counting/smart-pointer system. So I'm wondering is it possible to easily merge my stuff with Angelscript?

You can define different “behaviours” for your script classes, two of those behaviours are for adding a ref and releasing one. So it is very simple to support the ref counting of your C++ classes.

None

Advertisement

AngelScript doesn't do the reference counting internally, instead you need to register callbacks for addref & release, so the actual reference counting for application object is done in whatever way you prefer. If needed you can also register callbacks to allow angelscript's garbage collector to traverse the references to identify dead objects that are kept alive by circular references.

You can also use custom memory management with angelscript if you want angelscript to allocate memory with your own custom heap manager.

Give it a try, you'll find that angelscript is quite flexible and is most likely going to work without changes to your code.

If you have any doubts on how to solve something, feel free to come back here and ask for help.

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

WitchLord said:

AngelScript doesn't do the reference counting internally, instead you need to register callbacks for addref & release, so the actual reference counting for application object is done in whatever way you prefer. If needed you can also register callbacks to allow angelscript's garbage collector to traverse the references to identify dead objects that are kept alive by circular references.

You can also use custom memory management with angelscript if you want angelscript to allocate memory with your own custom heap manager.

Give it a try, you'll find that angelscript is quite flexible and is most likely going to work without changes to your code.

If you have any doubts on how to solve something, feel free to come back here and ask for help.

Regards,
Andreas

Wow! All that sounds perfect for my uses. I'll don't currently create any loops, however I was thinking I might want to implement a backup GC just to do heap compaction. Thanks, I will for sure give it a shot!

This topic is closed to new replies.

Advertisement