Prototype assignment to function within type?

Previous topic - Next topic

r0ber7

I have a type called config_type, which handles configuration files. It contains a PROTOTYPE which calls a function that generates config info.

Code (glbasic) Select

PROTOTYPE configtype_generate :

TYPE config_type
cfg_generate AS configtype_generate
ENDTYPE


I also have a server type, which (surprisingly) contains server info. It also contains a config_type, and a function which can be used to generate a config.

Code (glbasic) Select

TYPE server_type
       conf AS config_type

       FUNCTION srv_gen_cfg_in_servertype :
           // generate server config here
           // function is within server type
       ENDFUNCTION

      FUNCTION init :
          self.conf.cfg_generate = ?????
      ENDFUNCTION

ENDTYPE


Finally, I have a function that is not within the server type which can also generate a server config:

Code (glbasic) Select

FUNCTION srv_gen_cfg_not_in_servertype :
     // also generate config stuff, but this function is not in the server type
ENDFUNCTION


My question is about the assignment of the prototype in server_type.init():

If I set self.conf.cfg_generate = self.srv_gen_cfg_in_servertype, it fails.
But if I set self.conf.cfg_generate = srv_gen_cfg_not_in_servertype it works.

So, if I want to generate a config for the server type, I have to use a function from outside the server type to make the prototype assignment work. My question boils down to this.
Is there a way to set up a prototype within a type to be assigned to a function within another type?
This would make my code cleaner, since right now I'm using srv_gen_cfg_not_in_servertype() which needs a GLOBAL server_type to work with. This works fine, but it's not exactly OO. I know GLBasic has limited OO capabilities, I was just wondering if it is possible. :)


MrTAToad

Prototypes only work with functions outside types.  A way around it would be to get each prototype function to call a global extended type.

r0ber7

Quote from: MrTAToad on 2013-Apr-13
Prototypes only work with functions outside types.  A way around it would be to get each prototype function to call a global extended type.

Thanks.