10.5 Creating User Functions in C

For some specialized tasks, it may be desirable to write a C function that is callable from Vortex. New functionality might be more compactly or more efficiently encoded in C, such as a custom math function. Or a separate C library could be integrated, such as a custom encryption library.

Vortex supports adding new functions via the following process:

  1. A new user function is written in C, adhering to a specific syntax documented in the Vortex manual.
  2. The vufunc.c file is edited to make the Vortex API aware of the function.
  3. A new Vortex executable (texis ) is compile and linked.
  4. Old *.vtx files are deleted, and the new texis executable replaces the old one. The new function is now available as a builtin function to all scripts.

For full details on this process, consult the Vortex manual on Creating user functions .

Disadvantages

While adding a user function can speed up code that is best written in C rather than a scripting language, it is not always the best choice for implementation:

  • It requires the programmer to be well versed in C, including pointers, function pointers, dynamic memory allocation, and debugging. Often the headaches C causes, especially for the neophyte, far outweigh any run-time savings. Bugs in the code might not manifest themselves until well after the C function ends, making debugging a nightmare.

  • There may not be any speed advantage. Vortex is pretty fast at most operations; for small functions it may be just as fast - and much easier - to write the function in Vortex. Since Vortex already has powerful data processing functions, and the ability to execute external programs, it may be faster to <EXEC> the C code in a separate program and parse it in Vortex, especially as a quick prototype.

  • It's less portable. A C function means a new Vortex executable must be made if the hardware platform changes. Other Vortex users won't have the custom function in their texis executable.
Back: xtree - Continued Next: Multi-part File Uploads
Copyright © 2024 Thunderstone Software LLC. All rights reserved.