[Scilab-Dev] Overloading Scilab functions

Jonathan Blanchard BlanchardJ at ieee.org
Fri May 29 14:35:46 CEST 2009


Hi,

It's actually quite easy. But first you need to have a new type using
a TYPED_LIST_DATATYPE or a MATRIX_ORIENTED_TYPED_LIST_DATATYPE. The
first variable in those list can be used to defined the name of a new
type. So assuming that I used a type named MY_TYPE I can overload the
+ operators like this

function x = %MY_TYPE_a_MY_TYPE(a,b)
	x = my_add( a, b );
endfunction

This macro can be run in a toolbox init script. It is also possible to
over cross-typed operators like this :

function x = %s_a_My_TYPE(a,b)
	x = my_add( b, a );
endfunction

More info can be found in the scilab help with keyword overloading.



Jonathan Blanchard



On Fri, May 29, 2009 at 9:14 AM, Vincent Lejeune
<vincent.lejeune at institutoptique.fr> wrote:
> Hi,
>
> I wanted to know if it was possible to overload operator in SciLab, eg +,
> *,  .*, \, .\ ... and where I can find some sample of this feature in Scilab
> sources.
> For now, I use function like gpuAdd, gpuMult... on my custom gpuMatrix type,
> but I think it could be better if the enduser had only to write "C=A+B"
> instead of "C=gpuAdd(A,B)".
>
> Thank, Vincent.



More information about the dev mailing list