Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 03 Jun 2007
Offline Last Active Feb 05 2015 01:11 PM

Topics I've Started

Ownership problem of Funcdefs.

14 September 2013 - 02:39 PM

Hi and thanks for reading.

I've been looking at how to implement callback functions that I can pass to the application from script, and subsequently call from within the application.


A while back, when funcdefs didn't exist yet, I implemented my own Delegate class to solve this problem, but the problem with those is, that I cannot call object methods/actual delegates with those, since I cannot find a way to pass the script-class object reference to the application.

The documentation shows how to create a script class from within the application, and then call a function on that, but I have no idea how to pass a script object that was created in script to the application for calling.


Now I've updated to version 2.27.1 of Angelscript, and I found out it supports function definitions and delegates. I think this is a great solution to the problem. My delegate class for instance, couldn't match arguments, so it wasn't really safe. But with funcdefs I have an ownership problem.

When I create a delegate from an object method, the delegate object refs the object. So the object cannot be cleaned up while this delegate exists. Now if I proceed to pass this delegate to the application, I get an asIScriptFunction object. If I want to store that asIScriptFunction for later use, I reckon I'll have to increase it's ref.


Now the problem is, that the scripter is now no longer in control over when his object is destroyed, or when the delegate is released. If for instance, he registers an object method in a delegate as an event handler for, let's say, a key press, I'd have to return a certain handle, that he can later use to explicitly deregister this even, and thus "release" the asIScriptFunction object, in turn releasing the delegate, in turn releasing his object. This feals really redunant, since the delegate already represents this bond.


However if I don't ref the asIScriptFunction pointer in the application, I have no way of knowing when the delegate is released in script. Some kind of Weak referencing or a callback could work.....

I'm not sure which direction I want to take, or what is a good approach.
Is there a way to pass a script class object to the application so I can implement my own delegate?

Or should I stick to returning a new handle object that the scripter needs to keep reffed for as long as the delegate should stay alive?

In the last case generic func defs would be nice. Andreas talked about these when funcdefs were introduced, but I don't think they exist yet?

Any tips are appreciated. Many thanks,


Registering Operator Overloading with Angelscript

23 December 2010 - 10:50 AM

Hey Everyone! Thanks for reading.

I've been planning to do an angelscript implementation in my project for quite some time now. I've made a basic script engine implementation a while back, and only just came around to doing the actual bindings.

Now what confuses me is the Operator overloading. I've found some results on this forum of possibilities to actually register the operators using asBEHAVE_ADD and such, and I remember seeing something like this in the documentation a LONG time ago.

However now it seems defines like asBEHAVE_ADD no longer exist, and the manual states I should add functions like opopAdd and opAssign to my class, or make other wrapper functions for them and register those!

Is this really the only option now? 'cause being able to register the operators themselves seemed really awesome! I've made some defines/templates for wrapper functions like constructors and such, but doing all the operators too (especially if you have operators with different argument types for one class) will be a big hassle :-S

Is there no longer a way to register the operators directly? will my beloved asBEHAVE_ADD and friends ever return? ;-)

Kind regards!


(Proposition): Problem with No Default constructor.

05 September 2009 - 02:22 AM

OK sorry about this edit... I think I figured out my problem. I want to register an object by reference, and I want to call the object's constructor with parameters. I figured out however, that this is not possible without having a default constructor aswell! This is a problem for me, since not all objects have default constructors. When I register the object like this:
	r = scriptEngine.RegisterObjectType("Object", 0, asOBJ_REF); assert( r >= 0 );
	r = scriptEngine.RegisterObjectBehaviour("Object", asBEHAVE_FACTORY, "Object @f(int)",  asFUNCTIONPR(asObjectFactoryInt, (int) , Object*),asCALL_CDECL); assert( r >= 0 );
It doesn't work... it gives me the error:
ERROR: In D:/testscript.as: Data type can't be 'Object' at row: 3 col: 9
However after I add this line:
r = scriptEngine.RegisterObjectBehaviour("Object", asBEHAVE_FACTORY, "Object @f()",  asFUNCTION(asObjectFactory),asCALL_CDECL); assert( r >= 0 );
It works. This default constructor however, never gets called... but seems to be required to make the one with parameters, work. Is there anything I can do about this? I can't/don't want to facilitate default constructors for all my objects. Thanks! Kind regards, Wracky. [Edited by - Wracky on September 6, 2009 7:33:09 AM]

Registering reference types.

20 July 2009 - 10:09 PM

Hi and thanks for reading. Angelscript allows for me to register an object in two ways. Value types for passing by value, and reference types that are constructed with a factory function and are ref-counted. I've been looking at the way reference types are to be registered, and it seemed to me like it was rather "intrusive" to the application. As I understand it, I'll have to add ref-counting to the objects itself. So add a create, addRef and Release function for the object. So I'll have to change my classes in order to work with angelscript. I could add a parent class to all my exported classes that does the ref counting, but what troubles me more, is that I'll have to update the ref count in the functions that use these objects. I understand that this is a safe way of doing things, and that lua's way of NOT doing this can cause problems with garbage collection. If Angescript would indeed natively support smartpointers in the future, I could register them as Value types, and it would certainly deminish the amount of classes I need to adapt for use with angelscript. So what I'd like to ask is: How can I integrate this type of script "binding" into my application with as little code changes as possible. And is there an "elegant" way to do this? Thanks!

Tutorial: LibPNG: Loading PNG images from streams.

15 July 2009 - 12:33 AM

Hey everyone, and thanks for reading. I've written a tutorial for C++ on how to use libPNG to read a PNG image from streams, like the std::fstream or any std::istream for that matter. You can find my tutorial at http://www.piko3d.com It's the first tutorial I've ever written, and I though that perhaps some of you might find it interesting, or would have some comments/tips on how you like it and where I could improve it. It's a tutorial for people who seek more control over how and where to load their images, and are looking for something lighter then a general image library by using libPNG directly. LibPNG loads PNG files from FILE* normally, and this tutorial should give a bit more insight on how libPNG works and how you can use it's functions for providing your own data source (streams in this case), reading the PNG signature, and header info. Thanks! [Edited by - Wracky on July 15, 2009 11:37:15 AM]