plugins and managed types

Started by Superman95, Tue 13/09/2005 03:15:01

Previous topic - Next topic

Pumaman

QuoteYep, something similar I did in the past. I just thought maybe "agsplugin.h" could #ifdef-check for WINVER or maybe for _WINDEF_ (windef.h) to see if HWND is already declared

Yeah that's not a bad idea, I'll do that.

QuoteI haven't yet tried implemeting this but there seem to be one issue: the child object then needs to know if its parent is gone and thus therefore could set up some sort of a soft (unmanaged by ags) back reference.

Not necessarily -- as long as the parent keeps a reference to the child, it could call some sort of ParentIsDeleted() method on the child at the appropriate time, and the child could set a flag inside itself to remember this.

I'd rather not add functions to modify the reference count to the plugin API -- at the moment referencing counting is handled completely automatically by the script engine and it would seem to be inviting trouble to allow it to be manually adjusted.

QuoteOh, one more thing I forgot about: woud it be possible to get managed object address by its ID (I have a guess it's that key parameter) and the other way round?

That's a good point, it's difficult to re-link a parent and child object after de-serializing them at the moment, so I'll add some methods to help with that.

Scorpiorus

Quote from: Pumaman on Fri 16/09/2005 18:58:20Not necessarily -- as long as the parent keeps a reference to the child, it could call some sort of ParentIsDeleted() method on the child at the appropriate time, and the child could set a flag inside itself to remember this.

Yeah, that's what I meant with "to introduce plugin's internal reference count mechanism to avoid all these back references" I should have made myself clear. The object's flag effectively becomes a reference count and ParentIsDeleted would then decrease it acting like ReleaseRef. If I'll implement this functionality in a base class I can then use it for any other object derived from base. It just appeared to me like mirroring of what can already be done by the ags managed object pool itself that's why I wondered about possibility to expose ags functionality but I appreciate that it can cause nasty troubles and that the engine shouldn't really rely on a badly written plugin. :)

One more question if I may ask: how should I register static member functions?

Struct::StaticFunc(int a, int b, int c);

like this?
"Struct::StaticFunc^3"

or
"Struct::StaticFunc"

...because for me both of them seem to work.

Pumaman

It doesn't matter whether you include the ^3 or not.

The advantage of using it is that it allows you the scope of adding extra (optional) parameters to the method in future, which then allows your plugin to expose two different versions of the function for backwards compatibility.
ie. you can expose both of these:
"Struct::StaticFunc^3"
"Struct::StaticFunc^4"
but not both of these:
"Struct::StaticFunc^3"
"Struct::StaticFunc"

Scorpiorus

That's great! Thanks for clarifying!

Superman95

Talking about method overloading...can you do that in script now?

for instance:
foo(int one);
foo(int one, int two);

or is this just strickly available in the plugin.  Also, different types don't count as an overload...correct?
for instance:
foo(int one);
foo(string one);

and on a related topic...is it possible to do overrides?
for instance
struct base
{
   void foo(int one);
};

struct mystruct extends base
{
  void foo(int one);
}

so that mystruct.foo hides base.foo?

monkey0506

I'm pretty sure that function overloading is defined as two or more functions with the same name, but with different return types/parameter lists.

Pumaman

No, method overloading is not supported, and neither is polymorphism (an inherited class overriding a base class function).

Pumaman

QuoteOh, one more thing I forgot about: woud it be possible to get managed object address by its ID (I have a guess it's that key parameter) and the other way round?

Functions to do this have been added to 2.71 beta 6. Also, in beta 6 the RegisterMAnagedObject function returns the key so that you can save it somewhere at that point if you want to.

Scorpiorus

Quote from: Pumaman on Sun 18/09/2005 10:48:08Also, in beta 6 the RegisterMAnagedObject function returns the key so that you can save it somewhere at that point if you want to.

Ah, thanks for a note I didn't notice that bit -- quite handy!

SMF spam blocked by CleanTalk