object scripts

Mark Wieder mwieder at ahsoftware.net
Sun Feb 26 13:08:36 EST 2006


Geoff-

Sunday, February 26, 2006, 12:20:10 AM, you wrote:

> Heck, I think I could implement a significant chunk of OO in Rev as
> it stands right now, and it wouldn't even take that long. Just insert
> a front script, tag an object with a custom property representing its
> "class," test the class of the target in the front script to call the
> appropriate class routine, and encapsulate values in custom  
> properties. Automatic inheritance might be a bit tricky, but I'm sure
> something could be worked out.

> That would go a long way toward the principals of OO without having
> to change anything.

That's sort of what I'm doing now. Inheritance is actually fairly
easy. The hard part is that scripts are associated with screen objects
- you can't have objects that don't have screen representations.

For instance, I have a linked-list class that I use as a base class
for other classes. But there's no way to inherit the script without
making both the base and sub classes scripts of buttons or something
else. And adjusting front- and back- scripts accordingly. And paying
*very* careful attention to the message path.

-- Inheritance routines
local aClasses -- array of class/parent pairs

-- assign a parent class to a new class
on ClassFactory pNewClass, pParent
  put pNewClass into aClasses[pParent]
end ClassFactory

-- determine immediate parent class
function GetParent pClass
  if aClasses[pClass] is not empty then
    put aClasses[pClass] into pClass
  end if
  return pClass
end GetParent

-- determine base class, if any
function GetBaseClass pClass
  repeat while aClasses[pClass] is not empty
    put aClasses[pClass] into pClass
  end repeat
  return pClass
end GetBaseClass

-- 
-Mark Wieder
 mwieder at ahsoftware.net




More information about the use-livecode mailing list