anon_user_76973037

anon_user_76973037

About Me

EXPERTISE
Developer

Connect

LOCATION
Not Specified
WEBSITE

Houdini Skills

Availability

Not Specified

Recent Forum Posts

VEX structs & arrays of structs, lack of documentation Feb. 14, 2019, 1:02 p.m.

I scoured the official docs, this forum and the web for any more detailed documentation about VEX structs and arrays of those, but to no avail. So I have the following questions and hope that any answers given here could maybe helpfully be added to the VEX docs (which I generally find severely incomplete & limiting, causing hours of frustrated online searches):

1. Through trial & error I found out that structs cannot be defined in the wrangle editor itself, but need to be in an external file. What are the reasons?

2. Does VEX support nested structs at all? I.e. the type of a struct field is another struct type. This doesn't seem to compile:

// defined in an external source file

struct VG_MSTEdge {
  int a;
  int b;
  float cost;
}

struct VG_MST {
  VG_MSTEdge edges[];
  int result[];
  int maxID;
}

Produces these confusing error messages:

No matching function for VG_MST VG_MST(vector; int; int). Candidates are: VG_MST VG_MST(VG_MSTEdge; int; int) (7,1:13)
Not all code paths in the function ‘VG_MST’ return a value.

3. The following function computes the minimum spanning tree from a set of edges. Why does this produce an illegal indexing error in the highlighted line? Is there an error with the function parameters? What is the correct way to pass an array of structs?

Compiler error: "Call to undefined array index operator 'VG_MSTEdge VG_MSTEdge'"

struct VG_MSTEdge {
  int a;
  int b;
  float cost;
}

int vg_mst(const VG_MSTEdge edges[]; int maxID; int mst[]) {
    VG_DisjointSet g;
    g->init(maxID + 1);

    float costs[] = {};

    for(int i = len(edges); --i >= 0 {
        VG_MSTEdge e = edges[i]; /// <---- error, why?
        append(costs, e.cost);
    }
    int order[] = argsort(costs);

    foreach(int i; order) {
        VG_MSTEdge e = edges[i];
        if (!g->unified(e.a, e.b)) {
            g->union(e.a, e.b);
            append(mst, i);
        }
    }
    return len(mst);
}

4. Are the following forms of array declaration all equivalent? If so, why have that many syntax options? If not, what are the differences?

int[] foo = array();
int[] foo = {};
int foo[] = array();
int foo[] = {};

I'm really grateful for any answers to these questions! But as mentioned elsewhere, I also find it sad that after all this time and VEX being one of most powerful and exciting features of Houdini, it's been consistently one of the least documented aspects and is doing the whole VEX coding experience a huge disservice and causing ongoing unnecessary frustration…

As a maintainer of several large open source projects, I know from own experience that documentation always is one of the main pain points of a project, both for novice and experienced users. OTOH, Houdini costs serious $$$ and had a few decades to improve… so my hope for every new version update is a little more investment into docs rather than more features.

Thanks in advance!