How to make a program which returns a value through a variable
As mentioned in the previous section, returning a value from ASM program on a similar
way like TI-Basic functions return values causes problems with AMS 2.xx. So, in this
release of TIGCCLIB, another way for returning values (which works well unconditionally)
is introduced. This method will be ilustrated using a concrete example. Look the following
modified "directory" program given in the previous section:
#define RETURN_VALUE dirlist
#include <args.h>
#include <estack.h>
#include <vat.h>
int _ti89, _ti92plus;
void _main(void)
{
ESI argptr = top_estack;
SYM_ENTRY *SymPtr = SymFindFirst (GetSymstrArg (argptr), 1);
push_END_TAG ();
while (SymPtr)
{
push_ANSI_string (SymPtr->name);
SymPtr = SymFindNext ();
}
push_LIST_TAG ();
}
The only difference between this program and the program in the previous section is in
the usage of the RETURN_VALUE
directive: in this example, it is followed
with a variable name (dirlist
in this example). If
RETURN_VALUE
is followed with a variable name (which must be a legal
TI-Basic variable name in lowercase), the last value pushed to the expressions stack would
be stored in the TI-Basic variable with the given name. So, in this example, after execution
of the program, the result of the program (a folder list) will be stored in TI-Basic
variable called dirlist
(if such variable does not exist, it will be
created). See the previous section for more info about this example. I hope that this
explanation is clear enough, so more detailed explanation is not necessary.