rb-appscript: Accessing parent reference? - sourceforge-appscript

Is there an easy way to find the parent element reference of a reference?
For example, suppose I have the following reference:
ref = app("System Events").processes["Safari"].windows[1].buttons[1]
I would like to do something similar to the following:
ref.parent # => app("System Events").processes["Safari"].windows[1].buttons
Or even:
ref.parent # => app("System Events").processes["Safari"].windows[1]
I've looked over the documentation and guides and haven't been successful. I also tried a big no-no by monkey-patching the Appscript::Reference class and adding my own methods but it starts to break my specs in ways that are difficult to troubleshoot. I also thought about using eval but that seemed like a worse idea. Any thoughts?

After a bit of chin scratching, I think I might have a solution:
ref = app("System Events").processes["Safari"].windows[1].buttons[1]
ref.attributes[its.name.eq("AXParent")].value.get
Returns
[app("/System/Library/CoreServices/System Events.app").application_processes["Safari"].windows["rb-appscript: Accessing parent reference? - Stack Overflow"]]
Is that the kind of thing?
Ian

Related

SLICC indexing syntax

I have been digging through the cache-related parts of Gem5 (particularly the parts related to directories), and I've hit a bit of a snag.
This is the code for getDirectoryEntry(Addr addr), in src/mem/ruby/protocol/MESI_Two_Level-dir.sm:
Entry getDirectoryEntry(Addr addr), return_by_pointer="yes" {
Entry dir_entry := static_cast(Entry, "pointer", directory[addr]);
if (is_valid(dir_entry)) {
return dir_entry;
}
dir_entry := static_cast(Entry, "pointer",
directory.allocate(addr, new Entry));
return dir_entry;
}
Note the first line inside the function, where it says directory[addr].
directory was previously defined like so:
machine(MachineType:Directory, "MESI Two Level directory protocol")
: DirectoryMemory * directory;
...
I am trying to understand exactly what that directory[addr] bit of code means. Intuitively, it may be calling the C++ DirectoryMemory::lookup(Addr address) method, but I haven't found any code or documentation that supports that guess.
The DirectoryMemory class doesn't define an indexing operator, and there's also nothing in the SLICC page on the wiki that describes an indexing operator.
tl;dr: what does the indexing operator mean in SLICC? It it's defined for particular objects somewhere in the SLICC code, what should I be looking for to find its definition?
Thanks in advance!
Figured it out myself. It calls the lookup method in DirectoryMemory, as I suspected.

Spawn mob from other mods

I'm looking for a way to spawn entities from other mods. I found that for blocks and items there are a way to fetch them with
GameRegistry.findBlock()
but didnt found anything similar for mobs. I also didnt found any similar at forge off documentation. Is there any references/guides about communications with other mods?
I'm using MC 1.7.10/Forge 10.13.4
After a bit of code diving it looks like you can use EntityList.createEntityByName(String, World) to create an instance of an entity (it will return null if there's no entity with that name or another error occurs.) If you need to get an entity class from the name you can use the EntityList.stringToClassMapping map. Because 1.7.10 doesn't include any generics you'll have to manually cast the returned value from that map. As far as I can tell the type of the map is Map<String, Class>, as you probably already guessed.

What happened to Rhino Mocks' Arg<T>.Property

Arg<T>.Property is part of the documentation on inline constraints for Rhino Mocks v3.5, but I can't find it in v.3.6. What happened?
The documentation is here: http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx?AspxAutoDetectCookieSupport=1#SimpleConstraints
and Arg<T>.Property is mentioned in the constraints reference table.
This seems to be a bug in the documentation. When examining the Rhino.Mocks.dll (3.6.0.0) in the Object Browser I see that Rhino.Mocks.Arg<T> only offers the methods Is and List but not Property.
However Rhino.Mocks.Constraints contains the Property class. Using the "old" syntax you should be able to do the same:
AAA syntax (producing compile error):
myStub.Expect(x => x.MethodToCall(Arg<T>.Property.Value("PropertyName", myDesiredPropertyValue))).Result(myMockResult);
Old syntax (working):
myStub.Expect(x => x.MethodToCall(null)).Constraints(Property.Value("PropertyName", myDesiredPropertyValue)).Result(myMockResult);
The documentation says "You're probably used to IgnoreArguments(), Constraints() and RefOut(). [...] It is encouraged to use only Arg<T>, it is more consistent and easier to understand, even if sometimes a little more to write."
As Jeff Bridgman noted, you can also use Arg<T>.Matches:
myStub.Expect(x => x.MethodToCall(Arg<T>.Matches(m => m.PropertyName == myDesiredPropertyValue))).Result(myMockResult);
It has the advantage of being 'refactory safe', meaning that you can refactor the name of the property safely without the need to search for any 'magic strings'. It also meets the suggestion in the documentation to rather use Arg<T> instead of Constraints().

Name for program that converts between two formats?

This question is a little silly, but sometimes it's tough to figure out how to name things correctly. The conversion will parse a config file into XML and vice versa. I want to call the program MyCompany.Config2Xml, but the program also needs to be able to "Xml2Config".
I propose: ConfigParser
In keeping with SqlDataReader, TextReader, XmlReader etc I'd just call it ConfigReader and ConfigWriter.
Or, you could just go the serialization approach and then not have to worry about naming conventions.
CC for short:
ConfigConverter ?
Rather than ConfigParser as proposed by jeffamaphone (+1 for nice username), make it a verb:
parse-config
This makes it read nicely in scripts:
if ! parse-config < config-file > config.xml; then
exit 1
fi
I think it helps a lot to think about the verbs (methods) you intend to use with the class and the role the class plays in the application.
In other words if you envision the operation to be {class}.Get() or {class}.Load() then ConfigParser might be a good choice.
If on the other hand you have a corresponding {Class}.Set() or {class}.Save() operation then something like ConfigManager would be a better choice, particularly if the class will be used to isolate the application from the persistence of its configuration.
If the role of the class is nothing more than part of a standalone application or a step in a longer running process then I would would lean more towards class and method pairs that are more like Convert.ToXml() Convert.ToConfig() or Translate.FromXml() Translate.FromConfig().
General term seems like it would be format convertor, or transformatter (by analogy with transcoder). In terms of the specific names you discuss, I think I'd go with ConfigConvertor.
DaTransmogrifier
UberConvertPlus
Xml2Config2Xml
ConfiguratorX
'XConTrans'
or simply 'Via'
ConfXmlSwitcher :P

Find references to string/symbol/method

This relates to the Dolphin variant of Smalltalk.
I'm digging around in the image to try and figure this out but haven't
find the correct method invocation yet and I'm hoping someone might be
able to help shortcut this process. What I'm trying to do is to find
all methods (either within the entire system or, preferably, just
within a single class) which refer to a given string, symbol, or
method. I've found the #references family of methods in
SmalltalkSystem but have not had luck figuring out how to get them to
give back something resembling what I want.
The programmatic way, here we go
SmalltalkSystem current browseContainingText: 'Dolphin'.
I don't have Dolphin at hand, but the following code should work in all Smalltalk with the refactoring engine (this includes Dolphin):
result := BrowserEnvironment new matches: 'Dolphin'.
Then you can iterate over the results like this:
result classesAndSelectorsDo: [ :class :selector | ... ].