Wrapper script for C ++ how?
by Olexiy Kravchuk · in Torque 3D Professional · 10/13/2014 (12:30 pm) · 3 replies
I have matured a question. Suppose a situation that I want to create a new type of objec C ++ it has fields and methods, how can I make so that I could create and manage a new instance of this new type, by using the scripts. That is, I mean is how to make a wrapper for them?
#2
10/16/2014 (7:27 am)
Yes, thanks for the link, it's probably what I was looking for I read it, and now I have more questions, as I understand, that in order to create a wrapper, you need to create one more work than when you create a new type of objec, and I still have not figured out where you need it or not, must be wrapped all the internal methods and fields, each one individually, or sufficient to wrap only the class itself, and the rest will be configured automatically depending of type of marks within the fields of privacy?
#3
Look at Engine/gui/core/guiControl.h and Engine/gui/core/guiControl.cpp.
Nothing is exposed automatically - especially not based on access specifiers.
If you read those two source files carefully you will see that everything is not exposed - only what is needed from the script side. Model your new object's general structure this way and you should be fine.
Additionally, if you expect to create and manipulate your new custom object in the editor you must track down where the editor defines its list of editor objects and add yours. I don't remember where that is, unfortunately.
10/16/2014 (8:11 am)
Only expose what you want to expose.Look at Engine/gui/core/guiControl.h and Engine/gui/core/guiControl.cpp.
// in header:
// console exposure setup
DECLARE_CONOBJECT(GuiControl); // must have something like this - use your class name
DECLARE_CATEGORY( "Gui Core" ); // engine docs - nice to have but can be skipped I think
DECLARE_DESCRIPTION( "Base class for GUI controls. Can also be used as a generic container." ); // also engine docs
// callbacks
DECLARE_CALLBACK( void, onAdd, () );
// -----------------------------------------------
// in cpp file:
IMPLEMENT_CONOBJECT( GuiControl ); // must have this - use your class name
ConsoleDocClass( GuiControl, ... ); // this whole chunk is docs
IMPLEMENT_CALLBACK( GuiControl, onAdd, void, (), (),
"Called when the control object is registered with the system after the control has been created." ); // implements callbacks declared in header
// this is where fields are initialized - there are several examples
void GuiControl::initPersistFields()
{
addGroup( "Layout" );
addField("position", TypePoint2I, Offset(mBounds.point, GuiControl),
"The position relative to the parent control." );
...
}
// this exposes a script-side method. It contains a document block.
// there are several examles.
DefineEngineMethod( GuiControl, controlIsChild, bool, ( GuiControl* control ),,
"Test whether the given control is a direct or indirect child to this control.n"
"@param control The potential child control.n"
"@return True if the given control is a direct or indirect child to this control." )
{
if( !control )
return false;
return object->controlIsChild( control );
}Nothing is exposed automatically - especially not based on access specifiers.
If you read those two source files carefully you will see that everything is not exposed - only what is needed from the script side. Model your new object's general structure this way and you should be fine.
Additionally, if you expect to create and manipulate your new custom object in the editor you must track down where the editor defines its list of editor objects and add yours. I don't remember where that is, unfortunately.
Torque Owner Jesse Allen
Check out Class methods.