"Storing" User Defined VEX Functions

   3252   4   0
User Avatar
Member
2038 posts
Joined: Sept. 2015
Online
With Python we can use the Python Source Editor to hold our user defined functions.

And with digital assets we can something similar by creating a PythonModule.

I was wondering if there was a similar way to do that with functions we define for VEX.

From reading the help files it seems that if it is possible we will have to declare those functions before using them, but I can't seem to find information on how to “store” those defined functions elswehere.

In my search I've seen some references to dso files but can't make sense of it.

It's not an important issue but it could help reduce the amount of code lines and give better readability in my VEX “code text” windows.

I'm guessing it could be done in some way like at the top with an #Include line followed by the declarations? ( in the VEX “text box” of where the functions will be used ) plus whatever is needed to “store” those user defined functions.

Or maybe its much more involved than this?

Feedback on this appreciated - thanks.
Edited by BabaJ - July 27, 2016 16:44:53
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Hi
You can use #include “filename” just like you do in c/c++
Scroll down a little bit on this page: http://www.sidefx.com/docs/houdini15.5/vex/vcc [sidefx.com]

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
2038 posts
Joined: Sept. 2015
Online
Hi bonsak,

Thanks for the reference.

Works so easily…but I'm a bit confused about what the help file is saying elsewhere:

http://www.sidefx.com/docs/houdini15.5/vex/lang [sidefx.com]

Under the User Defined Functions section it tells you how one should define their functions which is how I did it in my *.h file.

Under the “Notes” part of that section it says functions must be declared first before being referenced.

But I didn't have to declare my function to use it in my VEX…I only had to put the #include at the top and was good to go.

So I'm not sure if they are using define and declare interchangeably or are using “reference” to mean something else in a certain context?



User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Hi
Writing “#include …” in your code is the same as actually writing the code from the external file at that place in your code. Except it happens in the compiler.
So if you write the “#include …” directive at the top of your code it's telling the compiler to include the code from the external file at the same place as the directive. So when you use the function later in your code it will already be declared at the location of the “#include” directive.

-b

EDIT: Add reference
Include directive [msdn.microsoft.com]
Edited by bonsak - July 28, 2016 08:00:57
http://www.racecar.no [www.racecar.no]
User Avatar
Member
2038 posts
Joined: Sept. 2015
Online
Ok this makes sense now.

My memory is bad too in the sense of forgetting why I used to write c code the way I did.

It's been a long time but I use to write somewhat small c code programs.

For readability and saving the hassle of having to scroll down to the main block of my program I use to only just declare my functions at the top, then after the main block of code is where I defined those functions.

Thanks again bonsak! for clarifying this.
  • Quick Links