As of build 1070 Anim8or supports user functions in ASL. The format is like normal functions:
<type>
name ( <type>
ident, <type>
ident, ...)
{
<statements>
}
There is a new type
void for functions that don't return a value and a new statement:
return <expr>;
As usual,
return statements can only appear in functions and don't have the <expr> for
void functions.
OK now the restrictions:
1. No forward declarations. Function headers must be followed by the definition in the form of a compound statement "{...}".
2. No recursion. Anim8or doesn't check for self-recursion yet (a last minute bug
). If you try it be prepared for chaos. I plan on allowing recursion but it's quite a bit of work to do efficiently so it may take a while.
3. Functions must be declared before they are called.
4. There is no "main" function yet. Any statements that aren't in a function are gathered into the "main" function, no matter where they appear. Kind of whacky, I know, but this allows you to more easily add functions to existing scripts. I'll fix this shortly by supporting a "main" structure.
5. No array parameters. All parameters and function results are the predefined types:
int,
string,
float,
point2,
point3,
quaternion,
float4x4,
shape,
meshdata,
spline,
material,
attribute,
texture,
object,
figure,
sequence,
scene, and
tridata.
6. All parameters are passed by value. Remember: types that represent objects within Anim8or (shape, meshdata, material, etc.) are actually handles so any changes to the parameter within a function affect the same object as outside the function. In the future I hope to add support for an
out modifier to return values through parameters as well as via the function result.
7. Function format parameter and local declarations are in a separate scope from global variables. Declarations within compound statements {} are still in the enclosing scope however. I hope to fix this soon as well but it could potentially break existing scripts. Let me know if you think this would be a big problem.
8. Not really function related, but you can use C++-style "//" comment delimiters now.
I'll post a couple of examples when I get a chance but hopefully this gives you something to start with!