makeclass('ug')

function ug.the()
  return tangible.find{plane="globals", center={0,0,0}, radius=1}[1]
  end

lis=tangible.find{plane="globals", center={0,0,0}, radius=1}
if #lis==0 then
  local ugid=tangible.build{class='ug', animstate={xyz={0,0,0}, plane='globals'}}
  print("The global table is "..tangible.id(ugid))
  end

function ug.set(var,val)
  ug.the()[var]=val
  end

function ug.get(var)
  return ug.the()[var]
  end

function login.cb_uglytimedaemon()
  if not ug.get('time') then ug.set('time',0) end
  while true do
    wait(1)
    ug.set('time',ug.get('time')+1)
    end
  end

function time() return ug.get('time') end

function isa(k1,k2,k3,k4)
  if k1==k2 or k1==k3 or k1==k4 then return true  end
  if k1==nil then return false end
  local mt=getmetatable(k1)
  if not mt then return false end
  return isa(mt.__index,k2,k3,k4)
  end

function tabcat(t1,t2)
  for i=1,#t2 do t1[#t1+1]=t2[i] end
  end

-- Example: multistart(function(t) return tangible.id(t)%3==0 end,function() print("Tangible "..tangible.id(tangible.place()).." here") end)
function multistart(fil,closure)
  local lis=tangible.find{plane="nowhere", center={0,0,100}, radius=1}
  tabcat(lis,tangible.find{plane="main", center={0,0,100}, radius=1})
  local filter=type(fil)=='function' and fil or function(t) return isa(t,fil) end
  for _,t in ipairs(lis) do if filter(t) then tangible.start(t,closure) end end
  end


  