Lpc Manpages

CONCEPT
        unions

DESCRIPTION
        Unions types are a declaration at compile time that a variable,
        function parameter or function return value can be one of
        several types.

        Except for type checks using #pragma rtt_checks they have no
        impact at runtime. There is no runtime union type, the concrete
        value type is one of the possibilities of the union type.

        Union types have no type names for themselves, they are declared
        anonymously with the declaration of the variable, function
        parameter or return type.

EXAMPLES
        1)
            int|string var;        // 'var' can be an int OR a string.


        2)
            int|float fun( object|closure var );

            // 'fun' can get 'var' as a closure OR an object while returning
            // an int OR a float.


        When using union types as array member types they must be enclosed
        with '< ... >':

        3)
            <int|string>* arr;

            // An array of ints AND strings, e.g. arr = ({"foo",1,"bar",2});


        4)
            int*|string*  arr;    

            // Either an array of ints OR an array of strings.
            // e.g. arr = ({1,2}); OR arr = ({"foo","bar"});


        5)
            < <int|string>*|object >* arr;

            // Now 'arr' can be an array of arrays of ints AND strings,
            // OR an array of objects:
            // e.g. arr = ({ ({"foo",1,"bar",2}) });
            //  OR  arr = ({ [/obj/beutel#123] }) ;

SEE ALSO
        types, structs, modifiers