GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
ChaiScript_Language Namespace Reference

Items in this namespace exist in the ChaiScript language runtime. They are not part of the C++ API. More...

Classes

class  Object
 Generic concept of a value in ChaiScript. More...
class  Map_Pair
 Item returned from a Range object from a Map. More...
class  Map
 Maps strings to Objects. More...
class  Container
 A concept implemented by string, Vector and Map. It is convertible to Range, default constructable and back_insertable. More...
class  string
 ChaiScript representation of std::string. It is an std::string but only some member are exposed to ChaiScript. More...
class  Range
 A concept in ChaiScript that is implemented by string, Vector and Map. It provides easy iteration over the elements in a container. More...
class  Const_Range
 A concept in ChaiScript that is implemented by string, Vector and Map. It provides easy iteration over the elements in a container. Contained values are const. More...
class  Vector
 A vector of Objects. More...
class  Type_Info
class  Function
 Represents a function object in ChaiScript. More...

Functions

string to_string (Object o)
 Converts o into a string.
void puts (Object o)
 Prints o to the terminal, without a trailing carriage return. Applies conversions to string automatically.
void print (Object o)
 Prints o to the terminal, with a trailing carriage return. Applies conversions to string automatically.
class ChaiScript_Language::Function max (Object a, Object b)
 Returns the max of a or b. Requires that operator>(a, b) exists Equivalent to.
Object min (Object a, Object b)
 Returns the min of a or b. Requires that operator<(a, b) exists.
bool even (Object x)
 Returns true if x is an even integer.
void for_each (Range c, Function f)
 Applies the function f over each element in the Range c.
Object map (Range c, Function f)
 Applies f over each element in the Range c, joining all the results.
Object foldl (Range c, Function f, Object initial)
 Starts with the initial value and applies the function f to it and the first element of the Range c. The result is then applied to the second element, and so on until the elements are exhausted.
Numeric sum (Range c)
 Returns the sum total of the values in the Range c.
Numeric product (Range c)
 Returns the product of the value in the Range c.
Object take (Range c, int num)
 Takes num elements from the Range c, returning them.
Object take_while (Range c, Function f)
 Takes elements from the Range c that match function f, stopping at the first non-match, returning them as a new Vector.
Object drop (Range c, int num)
 Drops num elements from the Range c, returning the remainder.
Object drop_while (Range c, Function f)
 Drops elements from the Range c that match f, stopping at the first non-match, returning the remainder.
Object reduce (Range c, Function f)
 Similar to foldl, this takes the first two elements as its starting values for f. This assumes Range c has at least 2 elements.
Object filter (Container c, Function f)
 Takes elements from Container c that match function f, return them.
string join (Range c, string delim)
 Joins the elements of the Range c into a string, delimiting each with the delim string.
Container reverse (Container c)
 Returns the contents of the Container c in reversed order.
Vector generate_range (Object x, Object y)
 Generates a new Vector filled with values starting at x and ending with y.
Object concat (Range x, Range y)
 Returns a new Range with x and y concatenated.
Vector collate (Object x, Object y)
 Returns a new Vector with x and y as its values.
Vector zip_with (Function f, Range x, Range y)
 Applies f to elements of x and y, returning a new Vector with the result of each application.
Vector zip (Range x, Range y)
 Collates elements of x and y, returning a new Vector with the result.
bool call_exists (Function f,...)
 returns true if there exists a call to the Function f that takes the given parameters
Range retro (Range)
 Reverses a Range object so that the elements are accessed in reverse.
Const_Range retro (Const_Range)
 Reverses a Const_Range object so that the elements are accessed in reverse.
void throw (Object)
 Raises the given object as an exception. Any type of object can be thrown.

Detailed Description

Items in this namespace exist in the ChaiScript language runtime. They are not part of the C++ API.

This file is not technically part of the ChaiScript API. It is used solely for generating Doxygen docs regarding the ChaiScript standard runtime library.

Function Documentation

◆ call_exists()

bool ChaiScript_Language::call_exists ( Function f,
... )

returns true if there exists a call to the Function f that takes the given parameters

Example:

eval> call_exists(`+`, 1, 2)
true
bool call_exists(Function f,...)
returns true if there exists a call to the Function f that takes the given parameters

◆ collate()

Vector ChaiScript_Language::collate ( Object x,
Object y )

Returns a new Vector with x and y as its values.

Example:

eval> collate(1, 2)
[1, 2]
Vector collate(Object x, Object y)
Returns a new Vector with x and y as its values.

◆ concat()

Object ChaiScript_Language::concat ( Range x,
Range y )

Returns a new Range with x and y concatenated.

Example:

eval> concat([1, 2, 3], [4, 5, 6])
[1, 2, 3, 4, 5, 6]
Object concat(Range x, Range y)
Returns a new Range with x and y concatenated.

◆ drop()

Object ChaiScript_Language::drop ( Range c,
int num )

Drops num elements from the Range c, returning the remainder.

Example:

eval> drop([1, 2, 3, 4], 2)
[3, 4]
Object drop(Range c, int num)
Drops num elements from the Range c, returning the remainder.
Returns
A container of the same type that was passed in

◆ drop_while()

Object ChaiScript_Language::drop_while ( Range c,
Function f )

Drops elements from the Range c that match f, stopping at the first non-match, returning the remainder.

Example:

eval> drop_while([1, 2, 3], odd)
[2, 3]
Object drop_while(Range c, Function f)
Drops elements from the Range c that match f, stopping at the first non-match, returning the remainde...

◆ even()

bool ChaiScript_Language::even ( Object x)

Returns true if x is an even integer.

Returns true if x is an odd integer.

Will also work on any non-integer type for which an operator%(x, int) exists

Example:

eval> even(4)
true
bool even(Object x)
Returns true if x is an even integer.

Will also work on any non-integer type for which an operator%(x, int) exists

Example:

eval> odd(4)
false

◆ filter()

Object ChaiScript_Language::filter ( Container c,
Function f )

Takes elements from Container c that match function f, return them.

Example:

eval> filter([1, 2, 3, 4], odd)
[1, 3]
Object filter(Container c, Function f)
Takes elements from Container c that match function f, return them.

◆ foldl()

Object ChaiScript_Language::foldl ( Range c,
Function f,
Object initial )

Starts with the initial value and applies the function f to it and the first element of the Range c. The result is then applied to the second element, and so on until the elements are exhausted.

Example:

eval> foldl([1, 2, 3, 4], `+`, 0)
10
Object foldl(Range c, Function f, Object initial)
Starts with the initial value and applies the function f to it and the first element of the Range c....

◆ for_each()

void ChaiScript_Language::for_each ( Range c,
Function f )

Applies the function f over each element in the Range c.

Example:

eval> for_each([1, 2, 3], print)
1
2
3
void for_each(Range c, Function f)
Applies the function f over each element in the Range c.
void print(Object o)
Prints o to the terminal, with a trailing carriage return. Applies conversions to string automaticall...

◆ generate_range()

Vector ChaiScript_Language::generate_range ( Object x,
Object y )

Generates a new Vector filled with values starting at x and ending with y.

Works on types supporting operator<=(x, y) and operator++(x)

Example:

eval> generate_range(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Vector generate_range(Object x, Object y)
Generates a new Vector filled with values starting at x and ending with y.

◆ join()

string ChaiScript_Language::join ( Range c,
string delim )

Joins the elements of the Range c into a string, delimiting each with the delim string.

Example:

eval> join([1, 2, 3], "*")
1*2*3
string join(Range c, string delim)
Joins the elements of the Range c into a string, delimiting each with the delim string.

◆ map()

Object ChaiScript_Language::map ( Range c,
Function f )

Applies f over each element in the Range c, joining all the results.

Example:

eval> map([1, 2, 3], odd)
[true, false, true]
Object map(Range c, Function f)
Applies f over each element in the Range c, joining all the results.

◆ max()

class ChaiScript_Language::Function ChaiScript_Language::max ( Object a,
Object b )

Returns the max of a or b. Requires that operator>(a, b) exists Equivalent to.

return a>b?a:b;

Example:

eval> max(4, 10)
10
class ChaiScript_Language::Function max(Object a, Object b)
Returns the max of a or b. Requires that operator>(a, b) exists Equivalent to.

◆ min()

Object ChaiScript_Language::min ( Object a,
Object b )

Returns the min of a or b. Requires that operator<(a, b) exists.

Equivalent to

return a<b?a:b;

Example:

eval> min(4, 10)
4
Object min(Object a, Object b)
Returns the min of a or b. Requires that operator<(a, b) exists.

◆ print()

void ChaiScript_Language::print ( Object o)

Prints o to the terminal, with a trailing carriage return. Applies conversions to string automatically.

eval> print("hello")
hello
eval>
See also
to_string
puts

◆ product()

Numeric ChaiScript_Language::product ( Range c)

Returns the product of the value in the Range c.

Example:

eval> product([1, 2, 3, 4])
24
Numeric product(Range c)
Returns the product of the value in the Range c.

Equivalent to:

foldl(c, `*`, 1.0);

◆ puts()

void ChaiScript_Language::puts ( Object o)

Prints o to the terminal, without a trailing carriage return. Applies conversions to string automatically.

eval> puts("hi, "); puts("there")
hi, thereeval>
void puts(Object o)
Prints o to the terminal, without a trailing carriage return. Applies conversions to string automatic...
See also
to_string
print

◆ reduce()

Object ChaiScript_Language::reduce ( Range c,
Function f )

Similar to foldl, this takes the first two elements as its starting values for f. This assumes Range c has at least 2 elements.

Example:

eval> reduce([1, 2, 3, 4], `+`)
10
Object reduce(Range c, Function f)
Similar to foldl, this takes the first two elements as its starting values for f. This assumes Range ...

◆ retro() [1/2]

Const_Range ChaiScript_Language::retro ( Const_Range )

Reverses a Const_Range object so that the elements are accessed in reverse.

◆ retro() [2/2]

Range ChaiScript_Language::retro ( Range )

Reverses a Range object so that the elements are accessed in reverse.

◆ reverse()

Container ChaiScript_Language::reverse ( Container c)

Returns the contents of the Container c in reversed order.

Example:

eval> reverse([1, 2, 3, 4, 5, 6, 7])
[7, 6, 5, 4, 3, 2, 1]
Container reverse(Container c)
Returns the contents of the Container c in reversed order.

◆ sum()

Numeric ChaiScript_Language::sum ( Range c)

Returns the sum total of the values in the Range c.

Example:

eval> sum([1, 2, 3, 4])
10
Numeric sum(Range c)
Returns the sum total of the values in the Range c.

Equivalent to:

foldl(c, `+`, 0.0);

◆ take()

Object ChaiScript_Language::take ( Range c,
int num )

Takes num elements from the Range c, returning them.

Example:

eval> take([1, 2, 3, 4], 2)
[1, 2]
Object take(Range c, int num)
Takes num elements from the Range c, returning them.
Returns
A container of the same type that was passed in

◆ take_while()

Object ChaiScript_Language::take_while ( Range c,
Function f )

Takes elements from the Range c that match function f, stopping at the first non-match, returning them as a new Vector.

Example:

eval> take_while([1, 2, 3], odd)
[1]
Object take_while(Range c, Function f)
Takes elements from the Range c that match function f, stopping at the first non-match,...
Returns
A container of the same type that was passed in

◆ throw()

void ChaiScript_Language::throw ( Object )

Raises the given object as an exception. Any type of object can be thrown.

Example:

eval> try { throw(1); } catch (e) { print("Exception caught: " + to_string(e)); }
Exception caught: 1
Env e
Definition Common.cc:2
string to_string(Object o)
Converts o into a string.
See also
try

◆ to_string()

string ChaiScript_Language::to_string ( Object o)

Converts o into a string.

eval> to_string(3).is_type("string") <br>
true<br>

◆ zip()

Vector ChaiScript_Language::zip ( Range x,
Range y )

Collates elements of x and y, returning a new Vector with the result.

Example:

eval> zip([1, 2, 3], [4, 5, 6])
[[1, 4], [2, 5], [3, 6]]
Vector zip(Range x, Range y)
Collates elements of x and y, returning a new Vector with the result.

◆ zip_with()

Vector ChaiScript_Language::zip_with ( Function f,
Range x,
Range y )

Applies f to elements of x and y, returning a new Vector with the result of each application.

Example:

eval> zip_with(`+`, [1, 2, 3], [4, 5, 6])
[5, 7, 9]
Vector zip_with(Function f, Range x, Range y)
Applies f to elements of x and y, returning a new Vector with the result of each application.