Copyright 2012 Two Lives Left Pty. Ltd.
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
  http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  
 Class.lua
 Compatible with Lua 5.1 (not 5.0).
      
      
function class(base)
    local c = {}    -- a new class instance
    if type(base) == 'table' then
        -- our new class is a shallow copy of the base class!
        for i,v in pairs(base) do
            c[i] = v
        end
        c._base = base
    end
    -- the class will be the metatable for all its objects,
    -- and they will look up their methods in it.
    c.__index = c
    -- expose a constructor which can be called by <classname>(<args>)
    local mt = {}
    mt.__call = function(class_tbl, ...)
        local obj = {}
        setmetatable(obj,c)
        if class_tbl.init then
            class_tbl.init(obj,...)
        else 
            -- make sure that any stuff from the base class is initialized!
            if base and base.init then
                base.init(obj, ...)
            end
        end
        
        return obj
    end
    c.is_a = function(self, klass)
        local m = getmetatable(self)
        while m do 
            if m == klass then return true end
            m = m._base
        end
        return false
    end
    setmetatable(c, mt)
    return c
end
      
      
local __parameter = parameter
parameter = {}
function parameter.text(t,n,i,f)
    local fn
    if type(f) == "function" then
       fn = function(a,b) f(b) end
    end
    __parameter.text(t,n,i,fn)
end
function parameter.watch(t,s)
    s = s or t
    local ufn = __parameter.watch(t)
    local fn = function() ufn(loadstring("return " .. s )()) end
    __parameter.watchfn(fn)
end
function parameter.colour(t,n,r,g,b,f)
    local c
    if not r or type(r) == "function" then
        c = colour()
        f = r
    elseif not g or type(g) == "function" then
        c = colour(r)
        f = g
    else
        c = colour(r,g,b)
    end
    local fn
    if type(f) == "function" then
       fn = function(a,b) f(b) end
    end
    __parameter.colour(t,n,c,fn)
end
parameter.color = parameter.colour
function parameter.number(t,n,a,b,i,f)
    local fn
    if not a or type(a) == "function" then
        f = a
        a = 0
        b = 1
        i = 0
    elseif not i or type(i) == "function" then
        f = i
        i = a
    end
    if type(f) == "function" then
       fn = function(a,b) f(b) end
    end
    __parameter.number(t,n,a,b,i,.001,fn)
end
function parameter.integer(t,n,a,b,i,f)
    local fn
    if not a or type(a) == "function" then
        f = a
        a = 0
        b = 1
        i = 0
    elseif not i or type(i) == "function" then
        f = i
        i = a
    end
    if type(f) == "function" then
       fn = function(a,b) f(b) end
    end
    __parameter.number(t,n,a,b,i,1,fn)
end
function parameter.action(n,f)
    __parameter.action(n,f)
end
function parameter.boolean(t,n,i,f)
    local fn
    if not f and type(i) == "function" then
        f = i
        i = true
    end
    if i == nil then
        i = true
    end
    if type(f) == "function" then
       fn = function(a,b) f(b) end
    end
    __parameter.bool(t,n,i,fn)
end
function parameter.select(t,n,o,i,f)
    local fn
    if not f and type(i) == "function" then
        f = i
        i = o[1]
    end
    if type(f) == "function" then
        fn = function(a,b) f(b) end
    end
    __parameter.select(t,n,o,i,fn)
end
      
      
function setup()
  print("hello world")
end
function draw()
  background(40,40,50)
  fill(150,200,30)
  stroke(200,30,150)
  strokeWidth(10)
  rect(20,20,100,100)
end