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

Iterate through objects in Context ?

Started by
2 comments, last by audioboy77 9 years, 4 months ago

Hi

Is it possible to iterate through the objects created in a particular context via the c++ interface? I would like to be able to do this, as on a script completion, I have the situation that some objects have not been destroyed.

My specific situation is that i am writing a scripting layer onto our UI library. This will allow creation of UI widgets and attaching them to the window's widget-tree. However, in our UI lib, attaching them to the widget tree also retains them. Therefore, they still exist when the script exits. This is desired in some cases, but I would like in some cases to be able to detach any widgets created from the script on script exit (without the script-writer needing to care about it)

I couldnt see a way to do this in the docs, so I guess its not possible but thought id ask anyway (and at least make a feature request from it).

Also, a question about strings: So far I have registered strings as a value type, is it possible to register them as a object type?

Thanks

Advertisement
What GUI lib are you using? In fltk (the one I use) you can access child widgets directly from the parent. So maybe you could store a pointer to the parent widget of the hierarchy tree (the main window) in the app and after the script finishes you can just access any left over widget from there.

There is no built-in way of knowing which context created which object. But you could make a way of keeping track of this by storing the active context when the factory behavior is called to create the object.

Object *Object_factory()
{
  Object *obj = new Object();
 
  // Keep track of which context created the object so it can later be found
  // (tracker is a fictional class, obviously)
  tracker.Insert(asGetActiveContext(), obj);
 
  return obj;
}

Yes, it is possible to register strings as reference types. Though you'll have to implement your own string class for this.

In my regression test suite I have one possible implementation:

http://svn.code.sf.net/p/angelscript/code/trunk/sdk/tests/test_feature/source/scriptstring.h

http://svn.code.sf.net/p/angelscript/code/trunk/sdk/tests/test_feature/source/scriptstring.cpp

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

Thanks for the info.

Both solutions make sense and I had already considered them, i just wondered if there was a direct way to get the created objects from the context itself.

FYI following a redesign, it will be no longer be an issue anyway. Instead of passing the window to the script, the app will now rather call a script function requesting the script to create a tree of widgets, which the app will then attach to the window. Something like UI_Object @ OnCreateObject(). So the app now just needs to release that one object when no longer needed.

@ Tzarls: its a custom UI library.

This topic is closed to new replies.

Advertisement