HomeIndex

Dinky Types

Dinky is a dynamically typed language so variables do not have a type, although the value they refer to does have a type. Dinky basic types are null, integer, float, string, table, array, and function.
null
A null or empty value.
If a null value is used in an arithmetic operation it is assumed to be zero, but note that null == 0 is false and null+0 == 0 is true. Many functions return null to destinate failure and doing a simple if(func()) won't distinguish between null and 0. A better test is if (func() == null)
local v = null
int
A 32 bit integer value from 2,147,483,648 to -2,147,483,644
local i = 1 local count = i+100 local ch = 'a' local h = 0x9076
float
A 32 bit floating point number
local f = 0.6 local time = 568.072
string
a string of characters
Individual characters can be accessed using s[1]. Indexing out of bounds will return 0. To check characters, use if (s[1] == 'a') and not if (s[1] == "a") as string contains characters, not strings.
Strings are immutable, so you can't do s[2] = 'x'
Strings, behave like C strings, are delimited by quotation marks(") and can contain escape sequences (\t, \n, \r, \\, \", \', \\, \0, \x##, and \u####.
More information about string functions can be found at Strings
local s = "this is a test" local t = "line 1\nline 2"
point
A point value of two floats.
Each value can be accessed using p.x and p.y. You can not set a value by doing p.x = 10, you have to do p = point(10,20) You can do p += point(10,2) or p = p1 + p1.
local p = point(6,10)
table
A table contains multiple key and value entries.
Values can be accessed using table.key or table["key"].
Values can be added using table.key <- value or table["key"] <- value.
Using table?.key or table?["key"] will return null if the key does not exist.
local t = { name = "Ted" } local h = {} local h = { "dinner": "soup" } local k = { ....name = "Donna" ....age = 67 } local age = k.age
array
An array of values.
Array's are a simple sequence of values starting at index 0.
Array's don't have to contain the same type of value
a = [ "text", 6, 9.3 ] // Valid array.
Arrays can be accessed using a[index].
Values can be replaced using a[index] = value.
Arrays can be defined using a = [1,2,3,4,5]
local a = [1,2,3,4,5,6,7,8,9,0] local names = [ "Ted", "Betty", "Delores", null ] local board = [[1,2,3],[4,5,6],[7,8,9]] local piece = board[2][1]
function
A value that is a pointer to a function
Functions in Dinky can be assigned to variables.
local f = function(int a) { return a+10 } local v = f(100) local t = { f = function() { return "sally" } } local e = t.f()
See Functions for more information about functions.