Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
-- This file:
-- http://angg.twu.net/youtube-db/ydb2.lua
-- http://angg.twu.net/youtube-db/ydb2.lua.html
--  (find-angg        "youtube-db/ydb2.lua")
-- Author:  Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2015may27
-- License: GPL3
--
-- This is an attempt to rewrite ydb using classes like "Set", "SetL",
-- and "YThing". It is currently VERY incomplete.
--
-- «.SetL»		(to "SetL")
-- «.SetL-tests»	(to "SetL-tests")
-- «.YThing»		(to "YThing")



-- «SetL» (to ".SetL")
SetL = Class {
  new = function () return SetL {set={}} end,
  type    = "SetL",
  __index = {
    has = function (s, k) return s.set[k] end,
    n   = function (s) return #s end,
    key = function (s, n) return s[n] end,
    val = function (s, k) return s.set[k] end,
    add = function (s, k, v)
        if not s:has(k) then s.set[k] = v or k; table.insert(s, k) end
        return s
      end,
    where = function (s, k) do
          for i=1,s:n() do if s:key(i) == k then return i end end
        end
      end,
    del = function (s, k)
        if s:has(k) then
          local i = s:where(k)
          local v = s:val(k)
          s.set[k] = nil
          table.remove(s, i)
          return s, v
        end
      end,
    pairs = function (s)
        local i=1
        return function ()
            local k = s:key(i)
            if k then
              local v = s:val(k)
              i = i + 1
              return k,v
            end
          end
      end,
    --
    PP = function (s) PP(s); return s end,
  },
}

--[[
-- «SetL-tests» (to ".SetL-tests")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "ydb2.lua"

SetL.new():add(2, 20):add(3, 30):PP()
SetL.new():add(2, 20):add(3, 30):del(2):PP()
SetL.new():add(2, 20):add(3, 30):del(3):PP()

s = SetL.new():add(2, 20):add(3, 30)
s = SetL.new():add(2, 20):add(3, 30):add(4, 40)
for k,v in s:pairs() do PP(k, v) end

PP(s)
s:del(2)
PP(s)

--]]




-- «YThing» (to ".YThing")
-- (yo)
YThing = Class {
  type    = "YThing",
  new = function (id)
      return YThing {id=id,
                     titles=SetL.new(),
                     fnames=SetL.new(),
                     tags=Set.new()}
    end,
  new_from_url   = function (url) end,
  new_from_fname = function (fname) end,
  __index = {
    title = function (yt, n) return yt.titles:key(n or 1) end,
    fname = function (yt, n) return yt.fnames:key(n or 1) end,
    addtitle = function (yt, ti) yt.titles:add(ti); return yt end,
    addfname = function (yt, fn) yt.fnames:add(fn); return yt end,
    addtag   = function (yt, ta) yt.tags:add(ta);   return yt end,
  },
}


--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "ydb2.lua"

--]]


-- Local Variables:
-- coding: raw-text-unix
-- End: