G2Basic 0.1.1 (1e793fc)
BASIC interpreter for microcontrollers
Loading...
Searching...
No Matches
Setup and output

Resetting the interpreter and routing its output. More...

Collaboration diagram for Setup and output:

Functions

void g2basic_init (void(*print_func)(const char *str))
 Reset the interpreter and set the text output callback.
 
void g2basic_set_number_output (void(*print_number)(double value))
 Replace the formatter for numbers printed by PRINT.
 

Detailed Description

Resetting the interpreter and routing its output.

Function Documentation

◆ g2basic_init()

void g2basic_init ( void(*)(const char *str)  print_func)

Reset the interpreter and set the text output callback.

Frees all variables, registered functions (custom ones included), and stored program lines, and clears the FOR and GOSUB stacks. It then registers the built-in functions selected at build time (see Built-in function backends) and resets the number formatter set by g2basic_set_number_output().

Call it once before any other function, and again to start over. Custom functions must be registered again after each call.

Parameters
print_funcReceives all interpreter output as NUL-terminated strings: PRINT values, separators, and newlines, LIST output, and RUN error messages. Each string is valid only during the call. NULL disables output.
Examples
interactive/main.c.

◆ g2basic_set_number_output()

void g2basic_set_number_output ( void(*)(double value)  print_number)

Replace the formatter for numbers printed by PRINT.

By default each value is formatted with 15 significant digits (%.15g) and passed to the text callback. With a formatter set, PRINT passes each value to print_number instead; separators and newlines still go to the text callback. The formatter is not called while the text callback is NULL. g2basic_init() resets it.

Parameters
print_numberNumber formatter, or NULL to restore the default.