»»»Home «««
»»»TELL «««
»»»Toped «««
»»»Ifaces «««
|
Table of Contents Functions are the basic building blocks of TELL code. Syntactically they look like C code. Below is the list of the main properties of TELL functions
The example below demonstrate the function definition and function call. box MOStran(point bound, real W, real L) { // draw some shapes return {{0,0},{10,8}}; // overlapping box } void Invertor(point bound, real NW, real NL, real PW, real PL) { MOStran(bound,NW,NL); // doing something box ptrActive = MOStran(bound,PW,PL); } An example of overloaded functions are Toped build-in functions like addbox, addpoly etc. described later in this manual.
Tell defines a dedicated data type for callback handling. It follows the function declaration syntax with two differences:
Two forms are possible. The second is anonymous.
Although admittedly a bit verbose, callback declaration syntax ensure that all necessary checks can be done in parse time. Once declared, the callback type can be used exactly as any other Tell type. Only the names of known functions can be assigned to a callback variables. They have to be prefixed by & as in the examples below. int simpleAdd(int a, int b) { return (a + b); } int simpleSub(int a, int b) { return (a - b); } // define a callback type unifunctype ... callback int unifunctype(int,int); // ... and a variable unifunc of that type unifunctype unifuncA = &simpleAdd; printf("Callback of type unifuncA - returns %d\n",unifuncA(2,3)); unifuncA = &simpleSub; printf("Callback of type unifuncA - returns %d\n",unifuncA(2,3)); // or define directly a variable unifunc of anonymous callback type callback int (int,int) unifuncB = &simpleAdd; printf("Callback of type unifuncB - returns %d\n",unifuncB(2,3)); unifuncB = &simpleSub; printf("Callback of type unifuncB - returns %d\n",unifuncB(2,3)); //same for the function argument list: //... using a pre-defined callback type void funcArguFuncA(int a, int b, unifunctype unifunc) { int result = unifunc(a,b); string buffer = sprintf ("%d fparam %d is %d", a, b, result); printf ("[%s] \n",buffer); } // ... or anonymous callback type void funcArguFuncB(int a, int b, callback int (int,int) unifunc) { int result = unifunc(a,b); string buffer = sprintf ("%d fparam %d is %d", a, b, result); printf ("[%s] \n",buffer); } funcArguFuncB(2,3,&simpleAdd); funcArguFuncB(2,3,&simpleSub); funcArguFuncA(2,3,&simpleAdd); funcArguFuncA(2,3,&simpleSub); Here is a quick example of a function calling itself int factoriel(real stop) { if (stop > 0) { int inter = factoriel(stop - 1); return (stop * inter); }; return 1; } TELL itself defines predominantly general purpose functions. Toped in turn internally defines and implements a list of functions ensuring its own functionality. In general the editor that interprets TELL shall define and implement its own internal functions. These functions will be parsed first as a part of the initialization phase of the interpreter, so that any internal commands (function calls) received from the command line (or file) can be properly handled. TELL functions described below are using directly the underlying C functions and more detailed description can be obtained directly from the C math library documentation. One of the few differences is that the trigonometric functions work with angle degrees instead of radians.
Example 1. Trigonometric functions point list arc(point center, int radius, int start, int stop, int numsteps) { real step = abs(stop -start) / numsteps; real current = start; point list the_arc; while (current <= stop) { point cur_point; cur_point.x = center.x + radius * cos(current); cur_point.y = center.y + radius * sin(current); current = current + step; the_arc[:+] = cur_point; } return the_arc; }
Returns the list length. Empty lists are valid and their length will be 0
Prints the value of a TELL variable. This function is rather temporary. It takes any type of argument and prints its value in the log window. It could be useful for some very basic debugging of the TELL script.
Write formatted data to the Tell log. This function mimics the syntax of the corresponding C function and works in a similar way. It implements the functionality of the C format tags including the flags, width, precision and length parameters.
The differences with the standard C printf implementation are listed below:
The definition of the format tags is widely available on external C/C++ reference sources - for example here Write formatted data to a string. Exactly like printf, but instead of the log console it writes all the output in the returned string.
The differences with the standard C implementation of sprintf are listed below:
The definition of the format tags is widely available on external C/C++ reference sources - for example here Executes external OS command. Current implementation is rather experimental. The function itself doesn’t return a result or status. The standard input and output is redirected to the Toped console and is highly dependent on the platform.
The primary purpose of this function is to launch external scripts. Exits the current session. Intended to be used from TELL scripts. If database contains unsaved objects the function will still ask to save it before exiting.
|