What does "introspection at runtime" mean?

Asked

Viewed 365 times

5

Looking for information about a graphic Toolkit in Lua, I found an explanation about lgi (GTK) that presented a great advantage: "...because it was written in C and has the ability to introspect at runtime, which facilitates the creation of bindings for other languages...". Can anyone help me better understand what "introspection at runtime means"?

1 answer

5


Type introspection allows the program to examine the structure of a type or object at runtime.

For example, at runtime, it is possible to know if a type X 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 function dir allows you to understand what type foo contain.

Reflection

Introspection is not the same as Reflection. The reflection allows to change the type or object data at execution time (the metadata), the introspection allows the consultation and analysis of the type information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.