introspection

How do you list all the namespaces in an instance of TCL?

橙三吉。 提交于 2019-12-06 02:53:48
How do you list all the namespaces loaded in an instance of tclsh? Chenz Try running this proc from the TCLer's Wiki proc listns {{parentns ::}} { set result [list] foreach ns [namespace children $parentns] { eval lappend result [listns $ns] lappend result $ns } return $result } When I run it, I get the following output: % listns ::platform ::activestate::teapot::link ::activestate::teapot ::activestate ::tcl ::clock ::tcl::info ::tcl::dict ::tcl::tm ::tcl::mathop ::tcl::unsupported ::tcl ::mathfunc ::tcl::chan ::tcl::string ::tcl % So, to get ALL namespaces, you simply need to do this: set

define_method with predefined keyword arguments

随声附和 提交于 2019-12-06 02:47:55
问题 I want to define a method that takes keyword arguments. I would like it to raise when keyword arguments are not provided, and I can code this myself - but ideally I would like to let Ruby do that for me. Also I would like to be able to inspect the freshly defined method using Method#parameters . If I use a shorthand double-splat (like **kwargs ) the actual structure I expect is not visible to parameters . I can of course do this: define_method(:foo) do | foo:, bar: | # ... end which achieves

unresponsive drag and drop in pygobject

只谈情不闲聊 提交于 2019-12-06 01:59:19
im trying to get drag and drop working well in pygobject, but it is slow and unresponsive, 90% of the time i have to wave the item i am dragging around before i can drop it successfully, can anyone see if i am doing it incorrectly or is this a bug with pygobject? here is my code from gi.repository import Gtk, GdkPixbuf, Gdk import os def got_data_cb(windowid, context, x, y, data, info, time): # Got data. tempArray = data.get_text().splitlines() for i in tempArray: i = i.replace('file://','') print i windowid.get_model().append([i]) context.finish(True, False, time) def drop_cb(windowid,

How do I loop over all the methods of a class in Perl?

随声附和 提交于 2019-12-05 20:18:44
问题 How do you loop over all the methods of a class in Perl? Are there any good online references to Perl introspection or reflection? 回答1: The recommendation Todd Gardner gave to use Moose is a good one, but the example code he chose isn't very helpful. If you're inspecting a non-Moose using class, you'd do something like this: use Some::Class; use Class::MOP; my $meta = Class::MOP::Class->initialize('Some::Class'); for my $meth ( $meta->get_all_methods ) { print $meth->fully_qualified_name, "\n

How can I inspect what is the default value for optional parameter in ruby's method?

廉价感情. 提交于 2019-12-05 20:00:44
问题 Given a class, class MyClass def index(arg1, arg2="hello") end end Is it possible to obtain the default value for arg2 , via some methods like Class#instance_method , or something? 回答1: It seems that only way we can inspect the values of method arguments is by having access to binding of method. Using Tracepoint class, we can get hold of such a binding object and then inspect the values of all optional parameters. We need to ensure that we invoke the desired method with only required

Python Introspection: How to get varnames of class methods?

混江龙づ霸主 提交于 2019-12-05 10:46:26
I want to get the names of the keyword arguments of the methods of a class. I think I understood how to get the names of the methods and how to get the variable names of a specific method, but I don't get how to combine these: class A(object): def A1(self, test1=None): self.test1 = test1 def A2(self, test2=None): self.test2 = test2 def A3(self): pass def A4(self, test4=None, test5=None): self.test4 = test4 self.test5 = test5 a = A() # to get the names of the methods: for methodname in a.__class__.__dict__.keys(): print methodname # to get the variable names of a specific method: for varname in

python: determine if a class is nested

孤人 提交于 2019-12-05 08:15:54
Suppose you have a python method that gets a type as parameter; is it possible to determine if the given type is a nested class? E.g. in this example: def show_type_info(t): print t.__name__ # print outer class name (if any) ... class SomeClass: pass class OuterClass: class InnerClass: pass show_type_info(SomeClass) show_type_info(OuterClass.InnerClass) I would like the call to show_type_info(OuterClass.InnerClass) to show also that InnerClass is defined inside OuterClass. AFAIK, given a class and no other information, you can't tell whether or not it's a nested class. However, see here for

Spy++ for PowerBuilder applications

大兔子大兔子 提交于 2019-12-05 06:18:46
I'm trying to write a tool which lets me inspect the state of a PowerBuilder-based application. What I'm thinking of is something like Spy++ (or, even nicer, 'Snoop' as it exists for .NET applications) which lets me inspect the object tree (and properties of objects) of some PowerBuilder-based GUI. I did the same for ordinary (MFC-based) applications as well as .NET applications already, but unfortunately I never developed an application in PowerBuilder myself, so I'm generally thinking about two problems at this point: Is there some API (preferably in Java or C/C++) available which lets one

Actionscript 3 introspection — function names

本秂侑毒 提交于 2019-12-05 05:49:48
问题 I am trying to iterate through each of the members of an object. For each member, I check to see if it is a function or not. If it is a function, I want to get the name of it and perform some logic based on the name of the function. I don't know if this is even possible though. Is it? Any tips? example: var mems: Object = getMemberNames(obj, true); for each(mem: Object in members) { if(!(mem is Function)) continue; var func: Function = Function(mem); //I want something like this: if(func

Check existence of global function in Swift

馋奶兔 提交于 2019-12-05 05:10:12
Is it possible to detect if some global function (not class method) is defined (in iOS)? Something like respondsToSelector in a class... Swift currently does not support looking up global functions. For C functions (most global functions from Apple's frameworks are C functions) there are at least two ways: using a weakly linked symbol the dynamic linker API: dlopen Both check dynamically (at runtime) if a symbol can be found. Here's an example that checks if UIGraphicsBeginImageContextWithOptions (introduced with iOS 4) is available: void UIGraphicsBeginImageContextWithOptions(CGSize size,