Loading...
Searching...
No Matches
Qore reflection Module

# reflection Module Introduction

The `reflection` module allows for Qore code to search and list the definitions and declarations in a Qore Program object.

This module is released under the MIT license (see `COPYING.MIT` in the source distribution for more information). The module is tagged as such in the module's header (meaning it can be loaded unconditionally regardless of how the Qore library was initialized).

To use the module in a Qore script, use the `%requires` directive as follows:

%requires reflection

To prohibit reflection in a Program object; use the PO_NO_REFLECTION sandbox restriction when creating the object or when setting sandboxing restrictions on the Program object.

Classes provided by this module:

- AbstractClass
- AbstractClassMember
- AbstractConstant
- AbstractMember
- AbstractMethod
- AbstractMethodVariant
- AbstractReflectionFunction
- AbstractVariant
- Class
- ClassConstant
- Constant
- ConstructorMethod
- ConstructorMethodVariant
- CopyMethod
- CopyMethodVariant
- DestructorMethod
- DestructorMethodVariant
- Function
- FunctionVariant
- GlobalVar
- Namespace
- NormalMember
- NormalMethod
- NormalMethodVariant
- PseudoClass
- PseudoMethod
- PseudoMethodVariant
- StaticMember
- StaticMethod
- StaticMethodVariant
- Type
- TypedHash
- TypedHashMember

Constants:

- Access Constants
- Code Flag Constants
- Modifier Constants
- Pseudo Class Constants
- Type Constants

Typed hashes:

- ClassAccessInfo

Objects created from reflection classes provided by this module are wrappers over the actual C++ objects; for this reason comparing different objects with the == or != operators will not return the expected results. To perform comparisons on reflection objects, use the `isEqual()` methods such as AbstractClass::isEqual(), AbstractMember::isEqual(), or Namespace::isEqual(), among others.

# Examples

Example:
  #!/usr/bin/env qore
  %new-style
  %require-types
  %strict-args
  %enable-all-warnings
  %requires reflection
  Class c = Class::forName("Condition");
  AbstractMethodVariant v = c.getVariant("wait", Class::forName("AbstractSmartLock").getType(), TimeoutType);
  printf("%s\n", v.toString());
  # produces the following output:
  # public int Condition::wait(object<AbstractSmartLock> lock, timeout timeout_ms = 0)

# reflection Module Release Notes

This module is always delivered with Qore and therefore mirrors the Qore version.