Jump to content

Custom VEX function input type


MJNorris

Recommended Posts

Hi there,

 

I'm trying to wrap my head around custom vex functions, mainly from a theoretical point at this stage so not really addressing a specific use, just general knowledge.

When I create a VEX function I believe that I have to specify exactly what type of data it is expecting from the arguments and exactly what type of data it will return.

eg.

 

function int my_function(float a){

	return int(a);

}

in which case I have to feed it an INT argument and it will always return an INT value.

 

My question is this, is there any way of creating a VEX function which can accept multiple arguments, but not fail if one or more of those arguments are absent when the function is called? Or better yet a way of taking a single argument with out specifying what type of data that argument should be?

I'm guessing that this is somehow possible as most of the existing Houdini VEX functions work with multiple flavours of input.

Thanks in advance.

M

 

Link to comment
Share on other sites

it's called function overloading. for details see http://www.sidefx.com/docs/houdini/vex/lang.html#functions

this is a quick basic example where VEX determines which function to use based on the argument types you feed to the function

int func(int a; float b){
    return int(a*b);
}

float func(float a; float b){
    return a*b;
}

printf("value is %d", func(2.0, 2.75)); //change the 2.0 to 2 to see the difference

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...