OK, in my MS Agent Remote Control program I needed to record the actions that one can do to the agent object. I have an agent object that wraps the COM object. Here's an example of a public method that does some action that I need to be able to "record" and playback:
- speak: aMessage
- self triggerCommandEvent.
self control speak: aMessage
Now, self control returns the COM object. The method: #triggerCommandEvent is where things get interesting, though. Every method that needs to be recorded and played back calls this method first thing. Now, here's the implementation of the #triggerCommandEvent:
- | stackFrame |
stackFrame := Processor activeProcess topFrame sender.
- selector: stackFrame method selector
arguments: stackFrame arguments)
The thing I like about this is that there are several ways to do this, but being able to walk the stack allows you to do some rather elegant things and some less typing...=) Now, the above code is different in every Smalltalk, but you can do it. You can even do this concept in most dynamic languages. I know this isn't the greatest show of Smalltalk's abilities, but it's one of those things that I thought was nifty.