What does "introspection at runtime" mean?

5

Looking for information about a Lua graphical toolkit, I found an explanation of lgi (GTK) that had one great advantage: "... because it was written in C and with introspection capability at runtime, which facilitates The creation of bindings for other languages ... ". Can anyone help me better understand what "introspection at runtime" means?

    
asked by anonymous 13.07.2014 / 23:10

1 answer

5

Introspection or introspection of types, allows the program to examine the structure of a type or object at runtime.

For example, at runtime, you can tell if an X type has a specific method / function.

An example in python would be:

class foo(object):
  def __init__(self, val):
    self.x = val
  def bar(self):
    return self.x

# dir permite a instrospecção
dir(foo(5))

# resultado
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__', 'bar', 'x']

The dir function allows you to understand what type foo contains.

Reflection

Introspection is not the same as Reflection. The reflection allows you to change the type or object data at runtime (the meta data), introspection allows the query and analysis of type information.

    
14.07.2014 / 01:13