What does "runtime introspection" mean?

Looking for information about a graphical toolkit in Lua, I found an explanation about LGI (GTK) that had a big advantage: "...because it was written in C and with runtime introspection capability, which makes it easy to creating bindings for other languages...". Can anyone help me better understand what "runtime introspection" means?

Author: anmaia, 2014-07-13

1 answers

Introspection, or 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 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 function dir allows you to understand what type foo contains.

Reflection

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

 5
Author: anmaia, 2014-07-14 14:19:59