Reflection?

Everything else that doesn't fall into one of the other PB categories.
Zach
Addict
Addict
Posts: 1678
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Reflection?

Post by Zach »

So I haphazardly came across a term for the kinds of things I wanted to do, but couldn't / don't know a way and apparently this is called Code Reflection.

Dubious source (Wikipedia) but assuming its accurate to some degree
A language supporting reflection provides a number of features available at runtime that would otherwise be very obscure to accomplish in a lower-level language. Some of these features are the abilities to:

Discover and modify source code constructions (such as code blocks, classes, methods, protocols, etc.) as a first-class object at runtime.
Convert a string matching the symbolic name of a class or function into a reference to or invocation of that class or function.
Evaluate a string as if it were a source code statement at runtime.
Create a new interpreter for the language's bytecode to give a new meaning or purpose for a programming construct.
Those two bolded lines are what I've always been most interested in, from the standpoint of allowing users to modify my Text RPG Engine for instance (add their own commands (and the logic to handle them), game mechanics, etc)

I'm mainly curious if PB is capable of this at all, or would it be suited to implementing such a thing?

For now there is scripting languages I can play with to some degree, but I figured it would be interesting to see if Fred or Freak had any opinion on this sort of functionality.
Fred
Administrator
Administrator
Posts: 18547
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Reflection?

Post by Fred »

No, PB doesn't support reflection. That's said, with "Runtime" keyword, it does allow to act on PB internal using strings.
Zach
Addict
Addict
Posts: 1678
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Reflection?

Post by Zach »

Alright, I didn't think so..

Is there any interest in implementing Reflection?
Fred wrote:That's said, with "Runtime" keyword, it does allow to act on PB internal using strings.
Does anyone know of a good easy to follow example showing how that works? I will consult Help library in the meantime

Thanks.
Post Reply