Gentee
  • Gentee script programming language
  • Language Reference
    • Lexical elements
    • Types
    • Declarations
    • Statements
    • Error handling
    • Expressions
    • Running programs
    • Multithreading
    • Include and import
  • Standard Library Reference
    • Archiving
    • Array
    • Boolean
    • Buffer
    • Characters
    • Console
    • Constants
    • Context
    • Cryptography
    • Encoding
    • Files
    • Float numbers
    • Integer
    • Map
    • Multithreading
    • Network
    • Object
    • Path
    • Process
    • Regular expressions
    • Runtime
    • Sets
    • Strings
    • System
    • Time
  • Go Integration
    • Reference
    • Compilation and execution
    • Advanced features
    • Playground
  • Change language
    • Русский
Powered by GitBook
On this page
  • Operators
  • Functions
  • Ctx(str input) str
  • CtxGet(str key) str
  • CtxIs(str key) bool
  • CtxSet(str key, str val) str
  • CtxSet(str key, bool b) str
  • CtxSet(str key, float f) str
  • CtxSet(str key, int i) str
  • CtxValue(str key) str

Was this helpful?

  1. Standard Library Reference

Context

PreviousConstantsNextCryptography

Last updated 5 years ago

Was this helpful?

There are no global variables in the Gentee language. One of the ways to exchange data is a special associative array of strings (context). Any function can safely add key-value pairs there or get a value by key. In addition, the context has the ability to substitute other existing values from the context. For example, if the pairs "a": "String A" and "b": "String B" has been defined, then "#a# and #b#" will return "String A and String B". The functions and operators for working with the context are described below.

Operators

Operator

Result

Description

# ident

str

The same as CtxGet(key), where ident is the context key.

## str

str

The same as Ctx(str). Specify any expression that returns a string.

ident #= str

str

The same as CtxSet(str key, str s), where ident is the context key.

ident #= bool

str

The same as CtxSet(str key, bool b), where ident is the context key.

ident #= float

str

The same as CtxSet(str key, float f), where ident is the context key.

ident #= int

str

The same as CtxSet(str key, int i), where ident is the context key.

run str {
  str s = ` #AºB#`
  AºB #= `ººº`
  b #= 71
  CD #= `#AºB# #b# == ` 
  return #CD + #b + ##s
}
// ººº 71 == 71 ººº

Functions

Ctx(str input) str

The Ctx function replaces substrings #keyname# in input string with the value of the corresponding key, if it exists.

run str {
    CtxSetBool(`qq`, true)
    CtxSetFloat(`ff`, 3.1415)
    CtxSet(`out`, "it is #qq# that PI equals #ff#")
    return Ctx("#out#. #notexist#")
}
// it is true that PI equals 3.1415. #notexist#

CtxGet(str key) str

The CtxGet function gets the value of the key key, replaces all occurrences of other keys in it, and returns the resulting string. If the specified key is missing, an empty string is returned.

func init {
   CtxSet(`a1`, `end`)
   CtxSet(`a2`, `=#a1#=`)
   CtxSet(`a3`, `+#a2#+#a1#`)
}

run str {
    init()
    return CtxGet(`a3`)
}
// +=end=+end

CtxIs(str key) bool

The CtxIs function returns true if there is a value with the specified key in the context. Otherwise, it returns false.

CtxSet(str key, str val) str

The CtxSet function adds a key and a value to the context. If the key already exists, it will be assigned a new value. The function returns the value of the key.

CtxSet(str key, bool b) str

The CtxSet function adds a key and a logical value b to the context. A boolean value will be converted to the string true or false. The function returns the value of the key.

CtxSet(str key, float f) str

The CtxSet function adds a key and a floating-point number f to the context. The number will be converted to a string. The function returns the value of the key.

CtxSet(str key, int i) str

The CtxSet function adds a key and an integer i to the context. The number will be converted to a string. The function returns the value of the key.

CtxValue(str key) str

The CtxValue function returns the value of the key key as is. Unlike the CtxGet function, it does not replace occurrences of other keys. If the specified key is missing, an empty string is returned.

run str {
    CtxSet(`test`, `?value`)
    CtxSet(`param`, `#test# ==`)
    return CtxValue(`param`) + CtxValue(`nop`) + CtxGet(`param`)
}
// #test# ==?value ==
Ctx( str input ) str
CtxGet( str key ) str
CtxIs( str key ) bool
CtxSet( str key, str val ) str
CtxSet( str key, bool b ) str
CtxSet( str key, float f ) str
CtxSet( str key, int i ) str
CtxValue( str key ) str