Evaluating External Functions

Once an external function has been defined, AutoLISP can invoke it with an kInvkSubrMsg request. When the ObjectARX application receives this request, it retrieves the external function's integer code by calling acedGetFunCode(). Then a switch statement, an if statement, or a function‑call table can select and call the indicated function handler. This is the function that the ObjectARX application defines to implement the external function. Note that the name of the handler and the name defined by acedDefun() (and therefore recognized by AutoLISP) are not necessarily the same name.

If the function handler expects arguments, it can retrieve their values by calling acedGetArgs(), which returns a pointer to a linked list of result buffers that contain the values passed from AutoLISP. If the handler expects no arguments, it does not need to call acedGetArgs() (it can do so anyway, to verify that no arguments were passed). Because it retrieves its arguments from a linked list, the function handler can also implement variable-length argument lists or varying argument types.

Note:

The function handler must verify the number and type of arguments passed to it, because there is no way to tell AutoLISP what the requirements are.

Function handlers that expect arguments can be written so that they prompt the user for values if acedGetArgs() returns a NULL argument list. This technique is often applied to external functions defined as AutoCAD commands.

A group of ObjectARX functions known as value-return functions (such as acedRetInt(), acedRetReal(), and acedRetPoint()) enable an external function to return a value to the AutoLISP expression that invoked it.

Arguments that are passed between external functions and AutoLISP must evaluate to one of the following types: integer, real (floating-point), string, point (represented in AutoLISP as a list of two or three real values), an entity name, a selection set name, the AutoLISP symbols t and nil, or a list that contains the previous elements. AutoLISP symbols other than t and nil are not passed to or from external functions, but an ObjectARX application can retrieve and set the value of AutoLISP symbols by calling acedGetSym() and acedPutSym().

If, for example, an external function in an ObjectARX application is called with a string, an integer, and a real argument, the AutoLISP version of such a function can be represented as follows:

(doitagain pstr iarg rarg) 

Assuming that the function has been defined with acedDefun(), an AutoCAD user can invoke it with the following expression:

Command: (doitagain “Starting width is” 3 7.12)

This call supplies values for the function's string, integer, and real number arguments, which the doitagain() function handler retrieves by a call to acedGetArgs(). For an example of retrieving arguments in this way, see the first example in Lists and Other Dynamically Allocated Data.