This is the portable version of the TeaScript (Standard) Host Application for 64 bit Linux (Ubuntu 22.04). 
The purpose is to run and execute script files written in the TeaScript language.

Please, read also the LICENSE.TXT and COPYRIGHT.TXT for usage conditions and permissions.

You don't need to install the software before usage. 
But for convenience reasons an installation instruction is provided below.


Table of Contents
==================================
- Usage without installation
- Manual installation
- TeaScript programming
- Contact / Support
- Core Library
- Known Issues
- Breaking changes and deprecation



=== Usage without installation ===
----------------------------------

Note: On Ubuntu 22.04. everything on the system for use TeaScript should be present already.
      If not and for other Linux distributions: The TeaScript binary needs libstdc++.so.6.0.30 or newer.

First you must unpack all files (the complete package) to any destination. Then

a) execute <package root>/bin/TeaScript for launch the interactive shell.
   Ctrl+C will quit the application, or when type :q and pressing enter.
   
   :help <enter> will show a list of internal commands, e.g., use :ls vars for list all 
   variables and functions available in the current present scopes.
   Internal commands for the TeaScript shell always starts with a colon.
   
   Entered text without a starting colon will be interpreted as TeaScript syntax and will be parsed + evaluated.
   
b) Invoke <package root>/bin/TeaScript with a filename which shall be executed, e.g.:
   ./bin/TeaScript examples/corelibrary_test01.tea
   
   You can pass arguments to the script like this:
   ./bin/TeaScript examples\gcd.tea 18 42
   

   ./bin/TeaScript --help will show the available modes and options.
   E.g., use -T for time measurement of bootstrap, parsing (, compile) and evaluation|execution time.
   or use -i for enter the interactive shell after the script file has been executed or it is suspended.

   Use --compile <file>.tea for compile a TeaScript file for the integrated TeaStackVM and save it as <file>.tea.tsb.
   .tsb files (TeaScript Binary files) can be executed directly with ./bin/TeaScript.
   Use --info <file>.tsb for print the header information of a TeaScript Binary.
   Use --printTSVM <file>.tsb|tea for get a listing ot the instructions for the TeaStackVM.



=== Manual installation ===
---------------------------

When doing a manual installation you are able to run and execute TeaScript files (*.tea) 
as well as to pass arbitrary parameters to TeaScript files.

1. Copy the complete unpacked TeaScript folder to a destination of your choice, e.g.
   /opt/TeaAgeSolutions/
2. All your TeaScript files must start with the following line (shebang):
   #!/opt/TeaAgeSolutions/TeaScript/bin/TeaScript

After that you can invoke TeaScript files like the following example (passing 2 parameters to the script):

examples\gcd.tea 42 18

If you see the output 6 everything is working correctly.


=== TeaScript programming === 
-----------------------------

Information about how to program TeaScript can be found on the webpage:
https://tea-age.solutions

Also you may have a look at the provided example script files.


=== Contact / Support ===
-------------------------

This software is a pre-release.
The behavior, API/ABI, command line arguments, contents of the package,
usage conditions + permissions and any other aspects of the software and the package may change 
in a non backwards compatible or a non upgradeable way without prior notice with any new (pre-)release.

If you encounter bugs or problems, have feature wishes or any other question you may contact:

contact |at| tea-age.solutions


New versions, the source code of the TeaScript C++ Library, the TeaScript Host Application as well as 
eventually used other (A)GPL software are made available here:
https://tea-age.solutions/downloads/


=== Core Library ===
--------------------

Some (maybe incomplete) documentation about the provided standard Core Library.

HINT: in interactive shell use command ':ls vars' for get a complete list of all present toplevel 
      variables and functions.
      Or use ':search str' for search any variable and function containing 'str'.

Variable Name           : Type              --> docu
-------------------------------------------------------------------------------------------
_version_major          :  i64              --> major version of TeaScript
_version_minor          :  i64              --> minor version of TeaScript
_version_patch          :  i64              --> patch version of TeaScript
_version_combined_number:  i64              --> combined version number for easily compare versions.
_version_build_date_time:  String           --> build date and time as string
_api_version            :  i64              --> version of Core Library API.
features                :  Tuple            --> with elements format, color, toml: Bool
                                                indicating whether the Library/Host Application was compiled with the features.
_init_core_stamp        :  f64              --> time stamp in fractional seconds from an unspecified time point during program start.
_core_config            :  i64              --> combined enum teascript::config::eConfig value used for boostrap the CoreLibrary.
_exit_success           :  i64              --> exit code for indicating success (used especially for exit/_exit)
_exit_failure           :  i64              --> exit code for indicating failure (used especially for exit/_exit)
void                    : NaV (Not a Value) --> Convenience for can write 'return void' if function shall return nothing.
PI                      :  f64              --> The constant number PI


Func Name               : Signature         --> docu
-------------------------------------------------------------------------------------------
_out                    : void ( String )   --> prints param1 (String) to stdout
_err                    : void ( String )   --> prints param1 (String) to stderr
print                   : void ( Any )      --> prints param to stdout, will do to-string conversion of the parameter.
println                 : void ( Any )      --> prints param + line feed to stdout, will do to-string conversion of the parameter.
readline                : String ( void )   --> read line from stdin (and blocks until line finished), 
                                                returns the read line without line feed.
_exit                   : void ( Any )      --> exits the script (with stack unwinding/scope cleanup) with param1 as return value.
                                                (this function never returns!)
exit                    : void ( Any )      --> (DEPRECATED!) same as _exit but will do to-number conversion on the parameter.
_strtonum               : i64|Bool ( String ) --> converts a String to i64. Returns Bool(false) on error. 
                                                This works only with real String parameters. alternative for '+str'.
_strtonumex             : i64|u8|u64|f64|Bool (String) --> converts a String to i64,u8,u64 or f64, Bool(false) on error.
                                                This works only with real String objects.
_numtostr               : String ( i64 )    --> converts a i64 to String. this works only with real i64 parameters. 
                                                Alternative for 'num % ""'
_f64toi64               : i64 (f64)         --> converts a f64 to i64. same effect as trunc() but yields a i64.
to_string               : String (val: Any) --> converts val to string (note: if val is an integer _numtostr is an alternative)
to_number               : i64|u8|u64|f64|Bool (Any) --> converts val to a Number. returns Bool(false) on error. 
                                                (note: if val is a String _strtonum / _strtonumex is an alternative)
_eval                   : Any ( String )    --> parses and evaluates the string as TeaScript code and returns its result.
eval_file               : Any ( String )    --> parses and evaluates the content of the file and returns its result. 
                                                All defined functions and variables in the top level scope will stay available.
fail                    : void ( void )     --> exits the script (with stack unwinding/scope cleanup) with 
                                                error_code _exit_failure (this function never returns!)
fail_with_error         : void ( i64 )      --> exits the script (with stack unwinding/scope cleanup) with the i64 error_code. 
                                                (this function never returns!)
fail_with_message       : void ( String, i64 )  --> prints String to stderr, exits the script (with stack unwinding/scope cleanup) 
                                                with the i64 error_code. (this function never returns!)
clock                   : f64 ( void )      --> gets the local wall clock time of the current day in (fractional) seconds as f64.
clock_utc               : f64 ( void )      --> gets the UTC time of the current day in (fractional) seconds as f64. 
                                                (note: This UTC time is with leap seconds!)
_timestamp              : f64 ( void )      --> gets the elapsed time in (fractional) seconds as f64 from an unspecified 
                                                time point during program start. Time is monotonic increasing.
sleep                   : void ( i64 )      --> sleeps (at least) for given amount of seconds.
random                  : i64 ( i64, i64 )  --> creates a random number in between [start,end]. start, end must be >= 0 and <= UINT_MAX.

min                     : Any ( Any, Any )  --> returns the minimum of a and b
max                     : Any ( Any, Any )  --> returns the maximum of a and b
clamp                   : Any ( val: Any, low: Any, high: Any ) --> returns low if val is less than low, high if val is greater
                                                than high, otherwise val. garbage in, garbage out.
swap                    : Any ( Any, Any )  --> swaps the values of a and b (a and b are passed via shared assign)
abs                     : Number ( Number ) --> returns the absolute value of n (as same type as n). n must be a Number.
trunc                   : f64 ( Number )    --> rounds the given Number towards zero as f64. 
                                                e.g. 1.9 will yield 1.0, -2.9 will yield -2.0.
floor                   : f64 ( Number )    --> rounds down the given Number to next smaller integer as f64. 
                                                e.g. 1.9 will yield 1.0, -2.1 will yield -3.0
ceil                    : f64 ( Number )    --> rounds up the given Number to next greater integer as f64. 
                                                e.g. 1.1 will yield 2.0, -1.9 will yield -1.0
round                   : f64 ( Number )    --> rounds up or down the given Number to nearest integer as f64.
                                                e.g. 1.1 will yield 1.0, 1.6 as well as 1.5 will yield 2.0
pow                     : f64 ( Any, i64 )  --> computes power of input with integer exponent. if exp is a float it will get truncated. 
                                                returns a f64. (will do to-number conversion on input)
sqrt                    : f64 ( Any )       --> computes the square root of given input (will do to-number conversion on input).
timevals                : Bool ( t: f64, HH: i64, MM: i64, S: i64, ms: i64 ) --> computes the hour, minute, second 
                                                and (optionally) millisecond part of given time in seconds (e.g. from clock())
                                                note: hours can be greater than 23/24, it will not be cut at day boundary!
timetostr               : Bool|String ( t, with_ms: Bool ) --> builds a 24 hour wall clock string with the 
                                                format HH:MM:SS.mmm (milliseconds are optional)
                                                note: if t is greater than 24 hours it will not be cut.
rolldice                : i64 ( eyes: i64 ) --> randomly rolls the dice and returns the result.
inc                     : Number ( Number (in/out), step: Number ) --> increments given Number by step (default 1)
dec                     : Number ( Number (in/out), step: Number ) --> decrements given Number by step (default 1)
_seq                    : Sequence (start, end, step: i64 )  --> creates an IntegerSequence of [start,end] with given step.
                                                                 If end is smaller start, step must be negative.
                                                                 A sequence starts at start and the next value is the result
                                                                 of current + step. If end cannot be reached by step exactly
                                                                 the value remains at the last current, e.g, _seq( 1, 10, 2 )
                                                                 will be 1, 3, 5, 7, 9.
                                                                 Sequences can be used in forall loops.

=== Tuple helper functions ===
_tuple_create           : Tuple ( ... )     --> creates a tuple from the passed parameters. 
                                                parameter count is variable and type Any.
_tuple_size             : i64 ( Tuple )     --> returns the element count of the Tuple
_tuple_same_types       : Bool ( Tuple, Tuple ) --> checks whether the 2 tuples have the same types in exactly the same order 
                                                (and with same names).
_tuple_val              : Any ( Tuple, i64 ) --> returns the value at given index.
_tuple_named_val        : Any ( Tuple, String ) --> returns the value with given name (or throws).
_tuple_set              : void ( Tuple, i64, Any ) --> sets the value at given index or throws if index not exist.
_tuple_named_set        : void ( Tuple, String, Any ) --> set the value with given name (or throws).
_tuple_append           : void ( Tuple, Any ) --> appends new value to the end as new element.
_tuple_named_append     : Bool ( Tuple, String, Any ) --> appends new value with given name to the end as new element 
                                                if the name not exist yet.
_tuple_insert           : void ( Tuple, i64, Any ) --> inserts new value at given index.
_tuple_named_insert     : void ( Tuple, i64, String, Any ) --> inserts a value with given name at given index.
_tuple_remove           : Bool ( Tuple, i64 ) --> removes element at given index, returns whether an element has been removed.
_tuple_named_remove     : Bool ( Tuple, String ) --> removes element with given name, returns whether an element has been removed.
_tuple_index_of         : i64 ( Tuple, String ) --> returns the index of the element with given name or -1
_tuple_name_of          : String ( Tuple, i64 ) --> returns the name of the element with given idx (or throws)
_tuple_swap             : void ( Tuple, i64, i64 ) --> swaps elements of given indices
tuple_print             : void ( Tuple, String, i64 ) --> prints (recursively) all (named) elements, for debugging 
                                                (String param is the "root" name, last param is for max nesting level)

=== "minimalistic string support" ===
_strlen                 : i64 ( String )    --> returns the length of the string in bytes (excluding the ending 0).
_strglyphs              : i64 ( String )    --> returns the utf-8 (Unicode) glyph count of the string (excluding the ending 0).
_strglyphtobytepos      : i64 ( String, i64 ) --> returns the byte position of the given glyph in given string, or -1 if out of range.
_strat                  : String ( String, i64 ) --> returns a substring of one complete UTF-8 code point where position points into.
                                                empty string if out of range.
_substr                 : String ( String, from: i64, count: i64 ) --> returns a substring [from, from+count). 
                                                count -1 means until end of string. returns empty string on invalid arguments.
_strfind                : i64 ( String, substring: String, offset: i64 ) --> searches for substring from offset and 
                                                returns found pos of first occurrence. -1 if not found.
_strfindreverse         : i64 ( String, substring: String, offset: i64 ) --> searches for substring from behind from offset and 
                                                returns found pos of first occurrence. -1 if not found.
_strreplacepos          : Bool ( str: String, start: i64, count: i64, new: String ) --> replaces the section [start, start+count) 
                                                in str with new. returns false on error, e.g. start is out of range.
strreplacefirst         : Bool ( str: String, what: String, new: String, offset: i64 := 0 ) --> replaces first occurrence of what
                                                with new starting from offset. returns true if a replacement happen.
strreplacelast          : Bool ( str: String, what: String, new: String, offset: i64 := 0 ) --> replaces last occurrence of what 
                                                with new starting from offset. returns true if a replacement happen.
strtrim                 : Bool ( str: String, set: String, leading: Bool, trailing: Bool ) --> trims the string if it starts or ends 
                                                with characters in given set.
strsplit                : Tuple (str: String, sep: String, skip_empty : Bool := false ) --> splits the given string at every
                                                occurring separator and returns a tuple wth the elements.
strjoin                 : String ( Tuple, sep: String, add_leading: Bool := false, add_trailing: Bool := false ) 
                                            --> joins all elements of a tuple to a string with given separator.
_strfromascii           : String|Bool ( char: Number ) --> returns a String build from the ascii char.
                                                For invalid chars (>127) Bool(false) will be returned.
utf8_begin              : UTF8_Iterator ( String ) --> creates an utf-8 iterator for the given string and 
                                                sets .cur to first utf-8 glyph.
utf8_end                : Bool ( UTF8_Iterator ) --> returns whether the given utf-8 iterator is at end already.
utf8_next               : UTF8_Iterator ( UTF8_Iterator ) --> sets the utf-8 iterator (.cur) to next utf-8 glyph or end of string.


=== "minimalistic (text) file io support" ===
NOTE: text files must be UTF-8 encoded. Pathes can be relative to "cwd" or absolute.

cwd                     : String ( void )   --> returns the current working directory as String
change_cwd              : Bool ( String )   --> changes the current working dir
tempdir                 : String ( void )   --> returns configured temp directory as String
path_exists             : Bool ( String )   --> returns whether path in String exists as directory or file.
file_exists             : Bool ( String )   --> returns whether the given file exists.
file_size               : i64 ( String )    --> returns file size in bytes. -1 on error / file not exists / is not a file.
last_modified           : String ( String ) --> returns the last modified time as String for the given path or empty string 
                                                if not exists/error.
create_dir              : Bool ( String, Bool )  --> creates directories for path in String. Bool == true means recursively.
path_delete             : Bool ( String )   --> deletes(!) file or (empty) directory.
file_copy               : Bool ( file: String, dest_dir: String, overwrite: Bool ) --> copies file to dest_dir if not exist 
                                                or overwrite is true.
file_copy_newer         : Bool ( file: String, dest_dir: String ) --> copies file to dest_dir if not exist 
                                                or file is newer as the file in dest_dir.
readtextfile            : String|Bool ( String ) --> reads the content of an UTF-8 text file and returns it in a String. 
                                                An optional BOM is removed.
writetextfile           : Bool ( file: String, str: String, overwrite: Bool, bom: Bool )  --> writes the content of String to 
                                                text file. An optional UTF-8 BOM can be written (last Bool param). 
                                                overwrite indicates if a prior existing file shall be overwritten (old content destroyed!)
readfile                : Buffer|Bool ( String ) --> reads the binary content of the file into a buffer. returns Bool(false) on error.
writefile               : Bool ( file: String, content: Buffer, overwrite: Bool ) --> writes the content of the Buffer to the file.
                                               overwrite indicates if a prior existing file shall be overwritten (old content destroyed!)

readdirfirst            : Tuple ( String )  --> returns the first direntry of given path (see direntry for details)
readdirnext             : Tuple ( Tuple )   --> returns the next direntry of given direntry (see direntry for details)

=== the direntry tuple ===
On Error or if directory is empty or if there are no more entries to iterate over the tuple has the following elements:
valid                   : Bool              --> here false always.
error                   : i64               --> if greater 0 it is the reported error code from std::filesystem / the OS.
path                    : String            --> the path which was investigated / tried to investigate.

In all other states the tuple has the following elements:
valid                   : Bool              --> here true always.
name                    : String            --> the name of the entry.
size                    : i64               --> the file size (for directories always 0)
last_modified           : String            --> last modified date/time as String with format "%F %T" (perfectly sortable)
is_file                 : Bool              --> true if entry is file, false otherwise.
is_dir                  : Bool              --> true if entry is directory, false otherwise.
path                    : String            --> the absolute and canonical path of the entry.
_handle                 : Passthrough       --> instance of std::filesystem::directory_iterator as Passthrough value.


=== TOML Support ===
readtomlstring          : Tuple ( String )  --> creates a named tuple from the given TOML formatted string (or false on error).
readtomlfile            : Tuple ( String )  --> creates a named tuple from the given TOML formatted file (or false on error).


=== Color Output Support ===
make_rgb                : i64 (r: i64, g: i64, b: i64)  --> makes a 32 bit rgb color (garbage in, garbage out)
cprint                  : void (i64, String)  --> prints the text in the given rgb color (only available with libfmt)
cprintln                : void (i64, String)  --> same as cprint but adds a new line to the end.

=== Format String Support === 
format                  : String ( format: String, ... )  --> formats the string with libfmt the same way as known from C++.

=== Buffer Support ===
General information:
Buffers are represented as contiguous memory and can be accessed and modified bytewise at byte boundaries (1 byte = 8 bit).
It is not possible to share assign from a single byte of a buffer.

The Subscript operator can be used for access and modify an existing byte.

Buffers will not grow behind its original capacity automatically (use _buf_resize), but its size will grow up to its capacity.

Memory will be freed automatically if last reference goes out of scope or being undef'ed.

Because TeaScript has only one signed integral type, I64, all setter and getter for signed types are operating with I64.
Because TeaScript has only U8 and U64 as unsigned integral types, all getter and setter using a bigger type than U8
are operating with U64 as type.

All getters and setters are operating in host byte order.

_buf                    : Buffer ( size: Number )  --> creates an empty Buffer (size == 0) with capacity 'size'.
_buf_size               : U64 ( Buffer )           --> returns the actual amount of used/filled bytes in the buffer.
_buf_capacity           : U64 ( Buffer )           --> returns the amount of allocated memory in bytes for the buffer.
buf_zero                : void ( Buffer )          --> fills the complete capacity of the buffer with zeroes. post: size == capacity
_buf_fill               : Bool ( Buffer, pos: Number, count: Number, val: U8 )  --> fills the buffer from pos up to pos + count with val.
_buf_fill32             : Bool ( Buffer, pos: Number, count: Number, val: U64 ) --> fills the buffer from pos up to pos + count 
                                                       with val as u32. The passed range must be dividable by 4 (sizeof u32).
_buf_resize             : Bool ( Buffer, size: Number )  --> resizes the buffer (shrink or grow). new values are added as zero. 
                                                       see _buf_fill also.
_buf_copy               : Bool ( dst: Buffer, dst_off: Number, src: Buffer, src_off: Number, len: Number )  
                                                   --> copies src buffer into dst buffer.
_buf_at                 : U8 ( Buffer, pos: Number )  --> returns byte at given position, throws on out of range.
_buf_get_u8             : U8|Bool ( Buffer, pos: Number )  --> gets an U8 from buffer at given position, returns Bool(false) on failure.
_buf_get_u16            : U64|Bool ( Buffer, pos: Number ) --> gets an U16 as U64 from buffer at given position, returns Bool(false) on failure.
_buf_get_u32            : U64|Bool ( Buffer, pos: Number ) --> gets an U32 as U64 from buffer at given position, returns Bool(false) on failure.
_buf_get_u64            : U64|Bool ( Buffer, pos: Number ) --> gets an U64 from buffer at given position, returns Bool(false) on failure.
_buf_get_i8             : I64|Bool ( Buffer, pos: Number ) --> gets an I8 as I64 from buffer at given position, returns Bool(false) on failure.
_buf_get_i16            : I64|Bool ( Buffer, pos: Number ) --> gets an I16 as I64 from buffer at given position, returns Bool(false) on failure.
_buf_get_i32            : I64|Bool ( Buffer, pos: Number ) --> gets an I32 as I64 from buffer at given position, returns Bool(false) on failure.
_buf_get_i64            : I64|Bool ( Buffer, pos: Number ) --> gets an I64 from buffer at given position, returns Bool(false) on failure.

For all setters apply: if pos == size the buffer will grow if the capacity is big enough.

_buf_set_u8             : Bool ( Buffer, pos: Number, val: U8 )  --> sets val as U8 in buffer at given position, returns true on success.
_buf_set_u16            : Bool ( Buffer, pos: Number, val: U64 ) --> sets val as U16 in buffer at given position, returns true on success.
_buf_set_u32            : Bool ( Buffer, pos: Number, val: U64 ) --> sets val as U32 in buffer at given position, returns true on success.
_buf_set_u64            : Bool ( Buffer, pos: Number, val: U64 ) --> sets val as U64 in buffer at given position, returns true on success.
_buf_set_i8             : Bool ( Buffer, pos: Number, val: I64 ) --> sets val as I8 in buffer at given position, returns true on success.
_buf_set_i16            : Bool ( Buffer, pos: Number, val: I64 ) --> sets val as I16 in buffer at given position, returns true on success.
_buf_set_i32            : Bool ( Buffer, pos: Number, val: I64 ) --> sets val as I32 in buffer at given position, returns true on success.
_buf_set_i64            : Bool ( Buffer, pos: Number, val: I64 ) --> sets val as I64 in buffer at given position, returns true on success.
_buf_set_string         : Bool ( Buffer, pos: Number, val: String )  --> writes the String (_without_ trailing 0!) val into the buffer 
                                                                     at given position, returns true on success.
_buf_get_string         : String|Bool ( Buffer, pos: Number, len: Number )  --> gets a String from buffer at given position, 
                                                                     must be valid UTF-8, returns Bool(false) on failure.
_buf_get_ascii          : String|Bool ( Buffer, pos: Number, len: Number )  --> gets a String from buffer at given position, 
                                                                     all values must be in range [0,127], returns Bool(false) on failure.


=== Known Issues ===
--------------------

Please see Known_Issues.txt

=== Breaking changes and deprecation ===

Please see Deprecation_and_Breaking_Changes.txt
