You are here: start » geeny » home » reference » language » datatypes

Data types

The following data types are supported by the scripting language:

  • Persistent:
    • Single token data types:
      • INTEGER
      • FLOAT
      • VECTOR
      • ATOM
      • REFERENCE (CLONE)
    • Lists:
      • INTEGERS
      • FLOATS
      • VECTORS
      • ATOMS
      • REFERENCES (CLONES)
      • ARRAY
    • Engine objects:
      • INSTANCE
      • INSTANCES

Single token data types

  • INTEGER
    • A 32 bit integer number
      • 0, -1, 5666
  • FLOAT
    • A 32 bit floating point number
      • 0.0, 1.001, -33.3
  • VECTOR
    • A 4-dimensional vector of FLOAT
      • |1,2.2,-3,-4.3|
      • |1,2,3| == |1,2,3,0|
      • |1| == |1,1,1,1|
  • ATOM
    • Symbol token. Represents a group of characters starting with ‘_’ or an alphabet character, which may also contain numerical characters, but may not be interrupted by whitespace or any special characters except for ‘_’ or single ‘:’.
      • ‘atom’ ‘atom2’ ‘atom_3’ ‘atom:1’
      • ‘not an atom’ ‘neither+++this-*!’ ‘nor::this’
      • ‘’ (nul atom)
    • A path atom is an atom containing one or more single path operators (:). Path atoms may be used in the same way as any other atom, however when used to create or access an object, a path atom is interpreted as full name, including the zone, ie ‘zone:object’.
  • REFERENCE
    • A persistent reference to a database OBJECT. Internally, a reference is represented as name#id, where name (type ATOM) is the template name of the OBJECT, and id (type INTEGER) is the replica id of the OBJECT.
    • Only 0 and positive integers are valid ids.
    • When an object is deleted from the database, all references to it are automatically cleared.
    • Calling a nul reference is always safe. The return value of a nul call is always nul. The same rule applies to prop access.
    • Database objects with id 0 are considered static database objects. All other ids represent dynamic database objects.
  • CLONE
    • A reference to an object that is automatically generated as dynamic. This data type is only valid as property, and is handled in the same way as REFERENCE in all other cases (ie local variables, parameters).
  • INSTANCE
    • A reference to engine object. When loaded from a file or initialized as property from template, the reference is nul. INSTANCE values are not saved to file.

Lists

A list is a dynamic array of the specified single token data type. The array index is 1-based, meaning that the first item in the list is accessed as: list_name[1].

Reading from a non-existing item in a list always returns nul. Writing into a non-existing item in a list is ignored.

  • INTEGERS
    • {0 15 27 -13}
  • FLOATS
    • {0.1 2.3 13.17}
  • VECTORS
    • {|1,2,3,0| |1,2,3,0| |1,2,3,0| |1,2,3,0|}
  • ATOMS
    • {‘haha’ ‘hehe0’ ‘hihi_32_x’}
  • REFERENCES
    • {GAME#0 X#13}
  • MEMBERS
    • {X#12 X#13}
  • ARRAY
    • A list of pointers to single tokens or lists. When initialized as property from template, a non-persistent ARRAY is always empty. When an object is loaded from a file, all properties pointed to by the ARRAY will now be allocated on the internal heap of the object.
  • INSTANCES
    • A list of engine objects. When loaded from a file or initialized as property from template, the list is empty.

Database objects

Template declaration:

BEGIN            <class>       <template_name> 
  [OBJECT        Parent      = <parent_template_name>]
  [OBJECT        Scripta     = <inheritance_list>] 
  [<TYPE>        <name>      = [<value>]]  
  [<TYPES>       <name>      = [ [{] [<value> [,] [<value> ...]] [}] ]] 
                           [ = <value> [,] [<value> ...] [}] ]
END

Unless specific functionality provided by the underlying engine is required, object <class> identifier is object.

When an object is instantiated from a template, the following occurs:

  • All the properties not defined by template are copied from its parent (and the parent’s parent, etc).
  • All branches and evals defined by script files listed in the inheritance list, are linked into the object.
  • When inheritance list is empty, the object will contain no compile-time branches or evals.
  • When inheritance list is not specified, the parent’s inheritance list is used
  • The parent’s inheritance list may be nested into the object’s inheritance list at any point in the list, using the inheritance (@) operator.
  • For each REFERENCE and REFERENCES property, all references are generated as: reference = template_name. Following the ATOM to REFERENCE conversion rules, this creates a reference to the static object instance (replica id 0). When the object does not exist, it is instantiated.
  • For each CLONE and CLONES property, all references are generates as: reference = new template_name
  • For each script file listed in the inheritance list, starting with the first, branch ‘new’ (constructor) is called on the object. The constructor must not call the inherited branch ‘new’ on itself.

When an object instance is freed, the following occurs:

  • For each script file listed in the inheritance list, starting with the last, branch ‘free’ (constructor) is called on the object. The constructor must not call the inherited branch ‘free’ on itself.

To split a list across several lines, ‘=’ operator may be used.

Example template

file: “my_class.gee”

BEGIN            object        MY_CLASS  
  OBJECT         Parent      = MY_BASE_CLASS 
  OBJECT         Scripta     = @ my_class //default is @
  ATOM           Name        = ‘MY_CLASS’ 
  ATOM           Type        = MY_TYPE //'' may be omitted 
  INTEGER        Prop1       = 10    
  FLOATS         Prop2       = { 5.5 , 10 , 14.6 }       
  INTEGERS       Prop3       = 5 17 20 //{} and , may be omitted 
  ATOMS          Prop4       = { ‘haha’ hehe0 hihi_1_x }  
  VECTOR         Color       = | 1.0 29 0 0 | 
  REFERENCES     Game        = GAME GAME GAME GAME 
  CLONES         Members     = MY_BASE_CLASS MY_BASE_CLASS 
  ATOMS          LongList    = atom1 atom2 atom3
                             = atom4 atom1 atom2
                             = atom5 atom3
  VECTORS        Vectors     = |1 , 1 , 2| , |1.5 0|  13.5 , 0.0 
                             = |0.0|
END

Global maps

Using global maps, it is possible to define global identifiers.

BEGIN            global        CONST 
  <TYPE>         const_name  = [...]
END

CONST global identifiers are compiled into the code, and may not be altered in runtime. A REFERENCE or REFERENCES variable may not be constant, therefore, it is automatically considered an alias even when listed in CONST global maps.

BEGIN            global        ALIAS 
  <TYPE>         const_name  = [...]
END

ALIAS global identifiers are variables with a global scope. They may be altered in runtime. All database objects referred to by REFERENCE and REFERENCES global variables are created as first (following the ATOM to REFERENCE conversion rules).

Engine objects

Engine objects cannot be saved into a permanent file.

Access to engine objects is provided through INSTANCE handles. Thus:

REFERENCE databaseObject  = new ‘MY_CLASS’ 
ATOM result               = databaseObject.branchName('atom', 0, 0.5)
 
INSTANCE engineObject     = newTexture(128, 128) 
or: ITEXTURE engineObject = ... 
 
ATOM result               = engineObject.engineObjectFunction('atom', 0, 0.5)

Calling a nul instance is always safe. The return value of a nul call is always nul.

Variable scopes

Local variables

Included are branch and eval parameters.

Scope: current branch / eval

Examples:

branch foo(parameter_1, ATOM parameter_2)
  INTEGER local_var 
  REFERENCE global_object
  ..

The following local variables are implicitely present:

  • REFERENCE $
    • refers to object executing the branch or eval
  • REFERENCE *
    • refers to caller object
  • ARRAY &
    • contains all the parameters that branch or eval was originally called with.
      • may contain more or less parameters than formal list requires
      • while formal parameters may have converted or were set to default value, the & ARRAY contains exactly the list of parameters that were specified at calling time

Examples:

local_var = parameter_1      //equivalent to:
local_var = &[1]
local_var = parameter_2      //not necessarily equivalent to:
local_var = &[2]             
parameter_1 = local_var      //calling parameter is changed
parameter_2 = global_object  //calling parameter is NOT changed
global_object.property = ...
$.property = ...
*.property = ...
$.foo()

Object properties

Scope: global database

Examples:

REFERENCE x   = *
ATOM      x.a = ...

When a property being assigned to does not exist on an object, it is automatically created.

 
geeny/home/reference/language/datatypes.txt · Last modified: 2015/11/18 07:38 by matija
Recent changes · Show pagesource · Login