"Sputnik" help  
Sputnik Help
Language Reference - Classes - Class Cast Overrides - ToBinary

Class Cast Overrides - ToBinary

This allows a class to override the cast to Binary.

class Test
{
    my $i;
    my $j;
    Function __Construct($i, $j)
    {
        @this->$i = $i;
        @this->$j = $j;
    }
    Function __ToBinary()
    {
        say "__ToBinary has been run";
        return Pack("ii", $i, $j);
    }
}

my $a = new Test(64, 10);
printr (Binary)$a;

// PRINTS
// __ToBinary has been run
// Binary
// (
//     [0] => 0x40 [64] (@)
//     [1] => 0x00 [0] (.)
//     [2] => 0x00 [0] (.)
//     [3] => 0x00 [0] (.)
//     [4] => 0x0A [10] (.)
//     [5] => 0x00 [0] (.)
//     [6] => 0x00 [0] (.)
//     [7] => 0x00 [0] (.)
// )

A full list of all possible cast overrides can be found here.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org