Hello,
One of the questions with having meta objects for variables (Slots and Globals)
is: For what is is good?
Here is one example… in early stage but working.
Imagine you want to “hook into” instance variable access. It can be done with
e.g. bytecode manipulation, or
on the AST level. But that is far from nice.
With the new first class variables, there is now a fun way to do it: MetaLinks.
Make a class TT with an instance var “t” and add an accessor.
Now we can define a MetaLink: it describes a call to a meta object that we wan
to do before, after or instead
of what our variable normally does. (default is #before):
| link |
link := MetaLink new
metaObject: Halt;
selector: #now.
This link says: “do a Halt now before where I will get installed”.
To install the link, just get the Slot meta object and set it using #link:
(TT slotNamed: #t) link: link.
This sets the link by replacing the Slot with a LinkWrapper Slot, and then
recompiles all using methods.
Thus evaluating:
TT new t
will get you a #halt.
Lots of things are not yet implemented (multiple links, uninstall, arguments,…)
but it starts to show how simple one can do quite powerful things.
Marcus