"Subclassing" int in Pike code

"Per Hedbor () @ Pike (-) importm?te f?r mailinglistan" <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <[email protected]>
> I want something that basically works like an int, but appears
> different in sprintf("%O"). This appears to work, but seems a little
> convoluted; also, have I missed anything?

I just made a minor change to pike8 that allows you to simply inherit
Gmp.mpz.

So, your example can now be written like so:

| class x
| {
|    inherit Gmp.mpz;
|    string _sprintf(int flag,mapping o) {
|       if( flag == 'O' )
|          return "0x"+digits(16);
|        return ::_sprintf(flag,o);
|    }
| }

Note that it does not really work with Gmp.bignum, aka the actual
integer class, since that one auto-converts to a native integer
whenever it is in range.

-- 
Per Hedbor
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.