There are three ways to implement functions in Stacksmith:

  1. Built-in functions - These look and are called like any function handler implemented in Hammer, but actually compile to an instruction you define. However, they are limited to taking no parameters, and you can currently only add one by directly editing the built-in function table in CParser.cpp.

  2. Host functions - These follow fairly freeform syntax, and are defined like host commands, using a table you pass to LEOAddHostFunctionsAndOffsetInstructions, and compile to an instruction as well. The return value of the function must be pushed on the stack by your instruction after all parameters have been removed.

  3. Provide a callNonexistentHandlerProc to the LEOContext and at that point handle any function for which no handler exists in the current message path. The number of parameters and the parameters themselves will have been pushed on the stack, and can be accessed using the utility function LEOGetParameterAtIndexFromEndOfStack. Once you are done, use the utility function LEOCleanUpHandlerParametersFromEndOfStack to remove your parameters from the stack.

See How to add commands to Stacksmith on how to create your own instructions, and how the general process of specifying a syntax table work in Stacksmith.