Collection of custom reaper scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. -- Basic gui stuff by forum user "spk77": https://forum.cockos.com/showthread.php?t=161557
  2. ------------- "class.lua" is copied from http://lua-users.org/wiki/SimpleLuaClasses -----------
  3. -- class.lua
  4. -- Compatible with Lua 5.1 (not 5.0).
  5. function class(base, init)
  6. local c = {} -- a new class instance
  7. if not init and type(base) == 'function' then
  8. init = base
  9. base = nil
  10. elseif type(base) == 'table' then
  11. -- our new class is a shallow copy of the base class!
  12. for i,v in pairs(base) do
  13. c[i] = v
  14. end
  15. c._base = base
  16. end
  17. -- the class will be the metatable for all its objects,
  18. -- and they will look up their methods in it.
  19. c.__index = c
  20. -- expose a constructor which can be called by <classname>(<args>)
  21. local mt = {}
  22. mt.__call = function(class_tbl, ...)
  23. local obj = {}
  24. setmetatable(obj,c)
  25. if init then
  26. init(obj,...)
  27. else
  28. -- make sure that any stuff from the base class is initialized!
  29. if base and base.init then
  30. base.init(obj, ...)
  31. end
  32. end
  33. return obj
  34. end
  35. c.init = init
  36. c.is_a = function(self, klass)
  37. local m = getmetatable(self)
  38. while m do
  39. if m == klass then return true end
  40. m = m._base
  41. end
  42. return false
  43. end
  44. setmetatable(c, mt)
  45. return c
  46. end
  47. ----------------------------------------------------------------------------------------