[Gambas-devel] Provide special auto-instance of a class

tobi tobias at ...692...
Thu Apr 5 01:25:28 CEST 2012


Me again,

> Hi,
> 
> I have a non-static class and want to derive a special object of it upon class load. The
> GB_AUTO_CREATABLE() macro doesn't really help because it's not about an ordinary object, I have to
> insert special values. The best would be if I could derive an object from that class, modify it
> behind the scenes and provide it for project-global use under a certain name. I read that there are
> no project-global variables in Gambas (I actually never needed them) so this is not an option.
> As an alternative I'd create a new static auto-creatable class that just inherits my ordinary class
> and overwrites its _new() special method. Despite I'm optimistic about that approach I want to ask
> if there is an even more elegant way? (I also can't think of any class that does suchlike, it's
> maybe just beyond my daily use of Gambas)
> 
> In particular, if it helps, it is about: The ncurses library provides an stdscr window after being
> initialised which represents the terminal in full dimensions. I wrote an (almost working) window
> class in which stdscr shall be encapsulated upon ncurses instanciation.
> 
> Regards,
> Tobi
> 

I wonder what's wrong with this:

GB_DESC CWindowDesc[] =
{
	GB_DECLARE("Window", sizeof(struct nc_window)),
	...
        GB_METHOD("_new", NULL, CWindow_new, "(x)i(y)i(w)i(h)i"),
	...
};

GB_DESC CStdscrDesc[] =
{
        GB_DECLARE("Stdscr", sizeof(struct nc_window)),
        GB_INHERITS("Window"),
        GB_AUTO_CREATABLE(),

        GB_METHOD("_new", NULL, CStdscr_new, NULL),

        GB_END_DECLARE
};

It gives a "Not enough arguments" error as soon as I use the Stdscr class, thus on its
auto-creation. If i replace GB_AUTO_CREATABLE() with GB_NOT_CREATABLE() the program starts but of
course I can't do anything with its properties (wait a minute, not-creatable means that _new()
isn't called at all?). I am able to overwrite the inherited function?
I'm sure I misunderstand something about inheritance or those IDs. Could anyone point me to
the right way?

Regards,
Tobi





More information about the Devel mailing list