|
G2Basic 0.1.1 (1e793fc)
BASIC interpreter for microcontrollers
|
Making C functions callable from BASIC expressions. More...
Functions | |
| int | g2basic_register_function (const char *name, int arg_count, double(*func_ptr)(double[], int)) |
| Make a C function callable from BASIC expressions. | |
Making C functions callable from BASIC expressions.
| int g2basic_register_function | ( | const char * | name, |
| int | arg_count, | ||
| double(*)(double[], int) | func_ptr | ||
| ) |
Make a C function callable from BASIC expressions.
BASIC code calls it as name(arg, ...). The interpreter checks the argument count before calling. It passes at most 8 arguments; more is the error too many function arguments. There is no error channel for the result: a NaN result is an ordinary value. Assigning NaN to a variable makes that variable read as undefined.
| name | Name used in BASIC; the string is copied. Names are case-sensitive, and the built-in functions are lowercase (sqrt). The name must be a valid identifier (a letter or underscore, then letters, digits, or underscores) to be callable; this is not validated. Must not be NULL. |
| arg_count | Required number of arguments from 0 to 8, or -1 to accept any number up to 8. A call with a different count fails with the error "function 'name' expects N arguments, got M". |
| func_ptr | Implementation. It receives the evaluated arguments and their count and returns the result. Must not be NULL; this is not checked. |
| 0 | The function is registered. |
| -1 | The name is already registered (built-in functions included), or memory allocation failed. An existing function is never replaced. |