Quote:
Originally Posted by 2di
but i have all my classes and member function/variables stored as a string
Why? Or may be more pertinently where did this data come from?
Ok the story is, I writing my scripting language, At a moment langage is mostly completed, so i working on the c++ classes support inside of the scripting language, U create your classes in C++, and using them inside of ur script.
I have special class ObjectContainer which can store pointers to different Objects
It looks like that:
-
void* _class;
-
ClassType _type;
-
string _name;
-
string _className;
Virtual machine has list of ObjectContainers, where each element represents some object which been created inside of the script;
every time its executes script line like that:
1)it searches ObjectContainer List for the "player" object
2)casting void* p into PlayerClass*
3)changing value to 10
This is a code i have at a moment
- void AssignToken(void* vClassContainer, string dataM, Token* token)
-
{
-
ClassContainer* container = reinterpret_cast<ClassContainer*>(vClassContainer);
-
if (container->_type == ct_Player)
-
{
-
Player* object = reinterpret_cast<Player*>(container->_class);
-
if (dataM == "positionX")
-
{
-
object->PositionX = token->intData();
-
}
-
}
-
}
where:
vClassContainer pointerto ObjectContainer;
dataM = "positionX"
token = pointer to a token with value (10);
this means that every time i am going to add new class, i need to write all this stupid if statements.
And this is what i want:
- #define M_cast(className) className* object = reinterpret_cast<className*>(container->_class);
-
#define M_assignToken(dataMemberName) object->dataMemberName = token->intData();
-
-
void AssignToken(void* vClassContainer, string dataM, Token* token)
-
{
-
-
ClassContainer* container = reinterpret_cast<ClassContainer*>(vClassContainer);
-
string className = container->_className;
-
-
M_cast(vClassContainer->_className);
-
M_assignToken(dataM);
-
}
Target of this scripting language is a AI engine, so this language has to be easily integrated. So all i am trying to do is to make integration of new classes as simple as possible.
classes data, wont be genereated more than once, for one particular project.
Thanks for the idea about maps, i am thinking about it at a moment.