p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C++ Programming (http://p2p.wrox.com/forumdisplay.php?f=89)
-   -   dynamic class/object access (http://p2p.wrox.com/showthread.php?t=27906)

tonyedmo April 9th, 2005 10:20 AM

dynamic class/object access
We use VB and VB scriptcontrol way to much where I work.
Some of the core processing happens with scripts for the scriptcontrol.
Needless to say it makes for some slow processing.
I am working to create a compatible interpreter for these scripts.
I am using java at the moment , but I want to port it to c++ down the road. Linux c++ specifically.
I am using the "Reflections" class in java, to allow script access to other objects in the program, without having to code the access for each specific class.
VBscript control uses the AddObject method to provide access to class objects to the script.
I would like to find out what I can use in c++ that could help in providing this functionality.

Lets say I had a class called Box that had width, length and height properties or methods. In my script I could write "Box.width = 2" my interpreter would be able to reference the Box.width method and set the value to 2.

Hope this is clear enough.....if not let me know, so I can attempt to do a better job of explaining.

Alan-LB April 10th, 2005 02:02 AM

class Box // Class of Box - this is a description not an Instance
  public: // Any client can access Public Methods
    void SetWidth(int Input); // Declaration of Method to set width
  private: // Members are only available through Methods
    int Width, Length, Height; // Class Members (Properties)

void Box::SetWidth(int Input) // Definition of Method to set width
  Width = Input;

Box MyBox; // Object (Instance) MyBox of Class Box

MyBox.SetWidth(2); // This will set the Width for the Object MyBox to 2


In C++ Properties are known as "Member Variables" or "Data Members"

Does this help??


merediths April 16th, 2005 03:07 PM

 hmmm I think he's trying to do that without access to the source code, judging by his reference to the Reflection API and the fact that he's writing an interperter, such that if I produced an object named TestObject with a method SomeFunc() and gave him only the bytecode, he would be able to make his interperter execute TestObject.SomeFunc().
 There's no simple way to examine the structure of a C++ class that I'm aware of at runtime, similiar to the Reflection API in java. It's possible, but non-trivial .. you would need to implement code to examine, for example, the VFUNCTION table and such. That is, you would essentially have to write your own analog to the Reflection API.
 You might want to look at the source code for some open source debuggers (e.g. GDB) .. perhaps that would get you started on your way.

Meredith Shaebanyan

All times are GMT -4. The time now is 04:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.