Types
MiniD is dynamically typed, meaning that there are types, but variables are not typed, only the values they hold. So it's perfectly legal to write
local x = 5; x = "hello"; x = [4, 5, 6];
There are three categories of types: null, basic types, and reference types.
null
null is the value with which all uninitialized variables are initialized. null is a type of its own, and has only one value, which is null. null always equals (and is identical to (using "is")) null. In multiple assignments, extra variables on the left-hand side are given the value null. When calling functions, if not all parameters are given values, they are given null instead.
Basic Types
| Type | Description |
| integer | Signed 32-bit integer |
| float | Double-precision IEEE 754 floating-point number |
| boolean | Truth value |
| character | Single UTF-32 codepoint |
An integer is the same as a D int: a 32-bit, signed integer.
A float is the same as a D double: a double-precision IEEE 754 floating-point number.
In Lua, there is only one number type, and it (usually) corresponds to a double-precision floating point number. While this simplifies the implementation and also allows for any value that a 32-bit integer can store to be stored, the problem with this is speed. Most calculations, in general, are performed using integers. Things like loop and array indices really only make sense with integers. It seems rather inefficient to use a 64-bit floating-point type to loop from 1 to 10.
A boolean is like D's bool. It can only hold the values true and false. You cannot compare bools or perform any kind of mathematical operations on them. You can only assign their value and test for equality.
A character is like D's dchar. It can hold any UTF-32 codepoint. You can compare characters, but they will be compared by value and not lexicographically. Characters can be concatenated together to form strings, and can be concatenated with strings as well.
Reference Types
| Type | Description |
| string | A UTF-32 string of text |
| table | A set of key-value pairs, where keys can be any type (except null and boolean) |
| array | A list of values of any type, indexable by consecutive integers starting at 0 |
| function | A reference to a function closure |
| class | A class type, from which instances can be created |
| instance | An instance of a class |
| namespace | A special sort of table for holding declared variables |
| thread | A collaborative thread of execution |
Strings are fairly obvious. In MiniD, they are UTF-32, for two reasons: one, there are no messy multibyte encodings to deal with as in UTF-8 or UTF-16. And two, using UTF-32 means that MiniD strings can hold virtually any character in any language ever to have existed (or not existed). Can't say the same about ASCII, or Latin-1, or whatever the current locale 8-bit character set happens to be.
In MiniD, unlike in D, strings are immutable. When concatenating strings, a new string is created; same with appending strings. Because this makes string manipulation rather awkward or inefficient, MiniD provides the StringBuffer class in the base library to serve as a mutable string type.
Tables are an important container type in MiniD. Because they can be indexed by almost any type (except null), and can hold almost any type (again, except null), they are very flexible. Tables do not have quite the power that they do in Lua, however; many of the object-oriented aspects that can be achieved in Lua are accomplished using classes in MiniD.
Arrays are what you'd expect - a collection of values of any type, indexed by integers. Indices start at 0, and go to the length of the array minus one (as in most C-style languages). Like in D, arrays can be compared for equality and ordering based on their contents. Two arrays are equal only if their lengths are the same, and all their elements are identical (that is, for all indices i in arrays A and B, if A[i] is B[i] holds true, the arrays are equal).
Arrays exist, like integral types, for performance reasons. In Lua 5, tables can act like arrays, based on an algorithm that detects if the table is being used as an array, in which case the values will be stored in a true array instead of in the hash map. This is complex, and a fancy algorithm will never be as fast as the real thing. When you need a list of values indexed by (contiguous) integers, use an array; otherwise, use a table.
Functions are references to function closures, either written in MiniD or created by the host program. A function closure has everything it needs to properly execute the function. See Functions for more information on closures.
Classes are class types. Unlike in D, classes are first-class objects; you can assign classes to variables, pass them to and return them from functions, put them in tables etc. From a class, an instance of the class can be created.
Instances are instances of classes. Each instance is associated with a particular class type, and has its own copies of its class's member variables.
Namespaces are a bit like tables. Their keys are restricted to strings, and they can hold null values. These are used mostly as symbol tables, for things like global variables, modules, and class and instance fields and methods.
Threads are created when you use a coroutine expression. They represent a separate thread of execution with its own call stack. Threads in MiniD work collaboratively; that is, a thread will only stop executing when it uses a yield expression or when it returns from its main function. See the functions section for more info.
