Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------------------------------------
- function def_class( iface )
- {
- return class( iface.__init(), iface );
- }
- function def_subclass( superclass, iface )
- {
- scdata = get_merged( superclass._data, iface.__init() );
- sciface = get_merged( superclass._super, iface );
- sciface.super = superclass;
- sciface.superCall = function( fn )
- {
- args = va_get_args();
- args.shift();
- this.super[ fn ].apply( this, args );
- };
- return class( scdata, sciface );
- }
- function new_class( def )
- {
- args = va_get_args();
- args.shift();
- inst = clone( def );
- inst.__construct.apply( inst, args );
- return inst;
- }
- // ------------------------------------------------------
- global testClass = def_class
- ({
- __init = function()
- {
- return { count = 1 };
- },
- __construct = function( count )
- {
- if( count )
- this.count = count;
- },
- start = function( message )
- {
- this.pushMessage( message );
- this.count++;
- },
- stop = function()
- {
- this.count--;
- },
- pushMessage = function( msg )
- {
- println( "MESSAGE >>>>>>> " $ msg );
- },
- });
- global testSubClass = def_subclass( testClass,
- {
- __init = function()
- {
- return { messages = [] };
- },
- __construct = function( count )
- {
- println( "constructing a subclass..." );
- this.superCall( "__construct", count );
- },
- pushMessage = function( msg )
- {
- println( "--------- override ---------" );
- this.messages.push( msg );
- this.superCall( "pushMessage", msg );
- println( "--------- end ---------" );
- },
- });
- //
- // TEST
- //
- A_inst = new_class( testClass, 41 );
- B_inst = new_class( testSubClass, 123 );
- A_inst.start( "test A" );
- B_inst.start( "test B" );
- println( "\ndata A:" );
- printvar( A_inst._data );
- println( "\ndata B:" );
- printvar( B_inst._data );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement