Getting Started

ObjectScript is a dynamically typed language. That means you do not have to specify the data type of a variable when you declare it,
and data types are converted automatically as needed during script execution. So, for example, you could define a variable as follows:

var a = 12;

And later, you could assign the same variable a string value, for example:

a = "Hello World!";

Because ObjectScript is dynamically typed, this assignment does not cause an error message.
ObjectScript is case-sensitive, null is not the same as Null, NULL, or any other variant.

object, array, function and userdata are not primitive types and could be used as named containers for values.

Nulls

Null is a type with a single value null. All variables have a null value by default, before a first assignment,
and you can assign null to a variable to delete it. ObjectScript uses null as a kind of non-value.

Bolleans

The boolean type has two values, false and true, which represent the traditional boolean values.
However, they do not hold a monopoly of condition values: In ObjectScript, any value may represent a condition. Conditionals (such as the ones in control structures)
consider false, null and NaN (not a number) as false and anything else as true.

Beware that ObjectScript considers both zero and the empty string as true in conditional tests.

Arrays

Functions

You can think of functions as procedures that your application can perform:

var max = function(a, b){ return a < b ? a : b }

Functions are first-class values in ObjectScript. That means that functions can be stored in variables, passed as arguments to other functions, and returned as results.
An unconventional, but quite convenient feature of ObjectScript is that functions may return multiple results:

Moreover, ObjectScript supports nested functions and closures. The nested functions are functions defined within another function. They are created
each time the outer function is invoked. In addition to that, each created function forms a lexical closure: the lexical scope of the outer function,
including any local variables and arguments, become part of the internal state of each nested function object, even after execution of the outer function concludes:

ObjectScript can call functions written in ObjectScript and functions written in C++ or C. All the standard library in ObjectScript is written in C++.
Application programs may define other functions in C.

Userdata

An userdata allows arbitrary C++ or C data to be stored in ObjectScript variables. It's used to represent new types created
by an application program or a library written in C++ or C.

Assignment and Multiple assignment operator

Assignment is the basic means of changing the value of a variable or a object property:

a = "Hello" .. " world!"
t.n = t.n + 1

ObjectScript allows multiple assignment, where a list of values is assigned to a list of variables in one step. Both lists have their elements separated by commas:

a, b = 1, 2

The variable a gets the value 1 and b gets 2. In a multiple assignment, ObjectScript first evaluates all values
and only then executes the assignments. Therefore, you can use a multiple assignment to swap two values, as in:

ObjectScript always adjusts the number of values to the number of variables. When the list of values is shorter than the list of variables,
the extra variables receive null as their values, when the list of values is longer, the extra values are silently discarded.

The last assignment in the above example shows a common mistake. To initialize a set of variables, you must provide a value for each one:

a, b, c = 0, 0, 0
print(a, b, c) --> 000

You can use multiple assignment simply to write several assignments in one line. But often you really need multiple assignment,
for example, to swap two values. A more frequent use is to collect multiple returns from function calls.

a, b = f()

`f()` returns two results: a gets the first and b gets the second.

Global Variables

Global variables do not need declarations. You simply assign a value to a global variable to create it. It is not an error to access a non-initialized variable,
you just get the special value `null` as the result.

print(a) --> null
a = 10
print(a) --> 10

Usually you do not need to delete global variables, if your variable is going to have a short life, you should use a local variable.
But, if you need to delete a global variable, just assign `null` to it.

a = null
print(a) --> null

After that, it is as if the variable had never been used. In other words, a global variable is existent if (and only if) it has a non-null value.

Environments and the Global Environment

Any reference to a global name v is syntactically translated to _E.v. Moreover, every function is compiled in the scope of an external
local variable called _E, so _E itself is never a global name in a function.

Despite the existence of this external _E variable and the translation of global names, _E is a completely regular name. In particular,
you can define new variables and parameters with that name. Each reference to a global name uses the _E that is visible at that point in the program,
following the usual visibility rules of ObjectScript.

Any object used as the value of _E is called an environment.

ObjectScript keeps a distinguished environment called the global environment. This value is kept at a special object in the C registry. In ObjectScript,
the variable _G is initialized with this same value.

When ObjectScript compiles a function, it initializes the value of its _E upvalue with the global environment. Therefore, by default,
global variables in ObjectScript code refer to entries in the global environment. Moreover, all standard libraries are loaded in the global environment
and several functions there operate on that environment.

You can execute any function with a different environment using Function.applyEnv method. For example lets view code of eval functions
inside of core.os file:

The first result value of iter_func indicates either valid or not valid current step, second and other return values are user used values.

Any iterator needs to keep some state between successive calls, so that it knows where it is and how to proceed from there. Closures provide an excellent
mechanism for that task. Remember that a closure is a function that accesses local variables from its enclosing function.

Empty dimensional properties

What about?

b = a[]
a[] = 2delete a[]

ObjectScript provides following special methods `__getempty`, `__setempty` and `__delempty` that you can use if necessary.

Object-oriented programming (OOP)

Object-oriented programming is a programming paradigm that uses abstraction to create models based on the real world.
It uses several techniques and paradigms, including modularity, polymorphism, and encapsulation.

ObjectScript is OOP language, also you can override arithmetic, bitwise, concatenation, comparison and unary operators.

Core Objects

ObjectScript has several objects included in its core, there are global variables named Object, Array, String, Number, Boolean and Function.

Every object in ObjectScript is an instance of the object Object and therefore inherits all its properties and methods.

The extends operator has syntax `extends exp1 exp2` where exp1 and exp2 are any valid expressions, it's equivalent to:

(function(exp1, exp2){
exp2.prototype = exp1
return exp2
})()

Encapsulation

In the previous example, IvanPerson does not need to know how the Person class's walk() method is implemented, but still can use that method.
The IvanPerson class doesn't need to explicitly define that method unless we want to change it. This is called encapsulation,
by which every class inherits the methods of its parent and only needs to define things it wishes to change.

Right, JS, PHP, there are lots of languages out there that are case sensitive.

I personally don't care for that language design decision. Doesn't really matter how many languages choose to implement it. At this point, the decision to be case sensitive or not seems to flow out of the "well, everyone else is case sensitive, so this one should be too" camp, which, albeit a reason, isn't necessarily a good one in my book.