What Is UDF
User-defined functions, or UDFs, are AUX functions stored in .aux files. In auxlab2, a UDF is typically loaded from disk, registered with the engine, and then called by its file name without the .aux extension.
Basic Form
A simple UDF file can start with a function definition like this:
function y = myudf(x)
y = x.sqrt
If this is saved as myudf.aux and the file is loaded, you can call it as:
out = myudf([1 4 9 16])
Multiple Outputs
A UDF can return more than one output.
function [sumv, diffv] = pair_ops(a, b)
sumv = a + b
diffv = a - b
Usage:
[s, d] = pair_ops(10, 3)
Member Functions
The current codebase also supports member-style UDF definitions.
member function out = myfunc(arg)
out = name ++ sprintf("%d", id)
This form is useful when the function is meant to operate in a member-call context.
Working With UDF Files In auxlab2
In the current auxlab2 application:
- choose
File > Open UDF...to load a.auxfile - the file name stem becomes the UDF name used for calls
- the current file can also be reopened quickly from the recent-UDF list
- when a watched UDF file changes on disk,
auxlab2can reload it
Under the hood, the app loads the file path, defines the UDF, and then registers it with the AUX engine.
Notes
- The file name matters. A file named
myudf.auxis expected to register asmyudf. - UDFs are part of the canonical help gap noted in the older documentation, so this page should keep growing as we verify more syntax details.
- For debugging a UDF in the current app, see Debugging UDFs.
Current source basis:
auxlab2/src/AuxEngineFacade.cppauxlab2/src/MainWindow.cppaux_engine/example_apps/aux2/myudf.auxauxlab2/myfunc.aux