Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationObject data type

Structures inherit the features of objects. Structures are basically prototypes or templates of object in that they pre-define functions and variables within themselves. This allows the application to define it's own loosely attached variables. Objects like this can be powerful containers for multiple variables. Just as before, the object pointer (->) symbol allows access to the object's internal properties.

Objects are defined using the { } notation as of version 1.6.3:

YASS
$obj = {}
  

Prior to 1.6.3, objects needed to be defined using the new object() syntax.

YASS
$x = {}
$x->$y = 10
print($x->$y)
  

In YASS, objects can be seen as structures without rules. It is important to note that if you are chaining these, you must define each inner variable as an object like so:

YASS
$x = {}
$x->$y = {}
$x->$y->$a = 10
$x->$y->$b = 15
print($x->$y->$a)
  

These inner values can also be assigned with functions, taking advantage of lambda functions makes this easy:

YASS
$x = {}
$x->$y = function() print (true) end function
$x->$y()
  

It is important to note that functions cannot be directly assigned to objects but must first be abstracted using lambda functions as above.

Objects became available in version 1.4.1 and cannot be used in versions prior to this.

ZPE 1.6.3 completely redesigned the way objects work underneath the compiler and interpreter to make it possible to perform other operations on objects. For example:

YASS
structure person
  $name = ["Jamie", "Balfour"]
  $age = 27
  $email = "test@jamiebalfour.scot"
end structure
function main($args)
  $p = new person()
  $first = $p->$name[0]
  $second = $p->$name[1]
end function
  

It should be noted that version 1.5.4 added an alternative syntax for defining un-prototyped objects using the JSON notation:

YASS
$person = {forename : "Jamie", surname : "Balfour"}
  

This was a big update that inlines ZPE with ECMAScript's definition of objects.

Version 1.6.5 also changed the way that the serialisation and object definitions of objects was performed by adding 'native functions' to the object:

YASS
$person = {forename : "Jamie", surname : "Balfour"}
$person->get_definition()
$person->serialize("test.zo")
  

It is also very important to note that all objects and structures use by reference variable assignment. This means that changing an object variable inside one function affects another.

YASS
$v = {name : "Test object", inner : {name : "Test inner object"}}
print($v)
$x = $v->inner
print($x)
$x->name = "Test inner object new"
print($v->inner->name)
  

In most cases this is desirable, however an easy way to get around this is to perform a copy on the object.

Serialization

As of version 1.5.2 it is also possible to serialize and deserialize objects and structures using ZPE's object serialise (save) and deserialise (open) functions:

ZPE 1.6.6 changed the way that serialisation works on objects so both syntaxes are shown below:

YASS
$x = {}
$x->$y = function() print(true) end function
$x->$y()
//ZPE 1.5.2+
$x.serialise("test.output")
//ZPE 1.6.6+
$x->serialise("test.output")
$y = deserialise("test.output")
        

Built-in objects

Version 1.7.4 further improves objects by adding inline access to internal objects and is by far the simplest method of using these internally defined classes. For example, ZPE defines a UIBuilder object internally:

YASS
$ui = new UIBuilder()
$ui->show()
  
Comments
Feedback 👍
Comments are sent via email to me.