GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
ChaiScript_Language::Function Class Reference

Represents a function object in ChaiScript. More...

#include <chaiscript_prelude_docs.hpp>

Public Member Functions

string get_annotation () const
 Returns the annotation description of the function.
int get_arity () const
 Returns the arity of the function, -1 if the function takes a variable number of parameters.
Vector get_contained_functions () const
 Returns a vector of the contained functions.
Function get_guard () const
 Returns a function guard as function.
Vector get_param_types () const
 Returns a vector of Type_Info objects that represent the param types for this function. The first value in the list is the return type.
bool has_guard () const
 Returns true if the function has a guard to it. Always returns false for a conglomerate function.
Object call (Vector t_params) const
 Calls the function with the given set of parameters and returns the value;.

Detailed Description

Represents a function object in ChaiScript.

A function object may be one function, such as:

var f = fun(x) { return x; }
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4

Or it may represent multiple functions

var f2 = `-`; // represents the unary - as well as the set of binary - operators
int f2(char c)
Definition test.cpp:51

Guarded function example

def f3(x) : x > 2 {
return x;
}

Examples in the function definitions below will reference these examples

Member Function Documentation

◆ call()

Object ChaiScript_Language::Function::call ( Vector t_params) const

Calls the function with the given set of parameters and returns the value;.

Example:

eval> `-`.call([2,1]);
1

◆ get_annotation()

string ChaiScript_Language::Function::get_annotation ( ) const

Returns the annotation description of the function.

◆ get_arity()

int ChaiScript_Language::Function::get_arity ( ) const

Returns the arity of the function, -1 if the function takes a variable number of parameters.

Example:

eval> f.get_arity()
1
eval> f2.get_arity()
-1

◆ get_contained_functions()

Vector ChaiScript_Language::Function::get_contained_functions ( ) const

Returns a vector of the contained functions.

Example:

eval> f.get_contained_functions().size()
0
eval> f2.get_contained_functions().size()
11
eval> var v = f2.get_contained_functions();
v[0].get_arity()
2

◆ get_guard()

Function ChaiScript_Language::Function::get_guard ( ) const

Returns a function guard as function.

Example:

eval> f.get_guard() // Throws exception
Function does not have a guard
eval> f3.get_guard().get_arity()
1
Represents a function object in ChaiScript.
Definition chaiscript_prelude_docs.hpp:478
Function get_guard() const
Returns a function guard as function.
int get_arity() const
Returns the arity of the function, -1 if the function takes a variable number of parameters.

◆ get_param_types()

Vector ChaiScript_Language::Function::get_param_types ( ) const

Returns a vector of Type_Info objects that represent the param types for this function. The first value in the list is the return type.

If this function is a conglomerate of several functions (get_contained_values().size() > 0) then the function returns as many Type_Info objects as it can. If the functions contained all have the same arity, then it represents the arity. If they have different arities, it returns only one value - the return type.

For each parameter that is the same type, the type is returned. If the types are different then a Type_Info for Object is returned.

Example:

eval> f2.get_param_types().size(); // Returns a Type_Info for Object for the return type
1

◆ has_guard()

bool ChaiScript_Language::Function::has_guard ( ) const

Returns true if the function has a guard to it. Always returns false for a conglomerate function.


The documentation for this class was generated from the following file: