Example scaffold and generation output
Konstantin Tomashevich edited this page Jun 8, 2017
·
1 revision
tab: " "
className: MyObject
vars:
Urho3D::PODVector <Urho3D::StringHash> myArray_ =$My Array
float myFloat_ =500.0f$My float
Urho3D::String myString_ ="StringValue"$My String
header:
#pragma once
#include <Urho3D/Scene/Component.h>
class MyObject : public Urho3D::Component
{
URHO3D_OBJECT (MyObject, Component)
protected:
//@Insert var list
public:
MyObject (Urho3D::Context *context);
virtual ~MyObject ();
static void RegisterObject (Urho3D::Context *context);
//@Insert vars getters and setters
};
object:
#include "MyObject.hpp"
#include <Urho3D/Core/Context.h>
MyObject::MyObject (Urho3D::Context *context) : Urho3D::Component (context),
//@Insert vars initialization
{
}
MyObject::~MyObject ()
{
}
void MyObject::RegisterObject (Urho3D::Context *context)
{
context->RegisterFactory <MyObject> ();
//@Insert attributes registration
}
//@Insert vars getters and setters
bindings:
#include <Urho3D/ThirdParty/AngelScript/angelscript.h>
#include <Urho3D/AngelScript/APITemplates.h>
//@Insert arrays getters and setters
void BindMyObject (asIScriptEngine *engine)
{
Urho3D::RegisterObject <MyObject> (engine, "MyObject");
//@Insert getters and setters bindings
}
lua scaffold-unwrapper/Main.lua MyObject.scaffold MyObject.hpp MyObject.cpp MyObjectBindings.cpp
#pragma once
#include <Urho3D/Scene/Component.h>
class MyObject : public Urho3D::Component
{
URHO3D_OBJECT (MyObject, Component)
protected:
Urho3D::PODVector <Urho3D::StringHash> myArray_;
float myFloat_;
Urho3D::String myString_;
public:
MyObject (Urho3D::Context *context);
virtual ~MyObject ();
static void RegisterObject (Urho3D::Context *context);
Urho3D::PODVector <Urho3D::StringHash> GetMyArray () const;
void SetMyArray (const Urho3D::PODVector <Urho3D::StringHash> & myArray);
Urho3D::VariantVector GetMyArrayAttribute () const;
void SetMyArrayAttribute (const Urho3D::VariantVector &myArray);
float GetMyFloat () const;
void SetMyFloat (float myFloat);
Urho3D::String GetMyString () const;
void SetMyString (const Urho3D::String & myString);
};
#include "MyObject.hpp"
#include <Urho3D/Core/Context.h>
MyObject::MyObject (Urho3D::Context *context) : Urho3D::Component (context),
myArray_ (),
myFloat_ (500.0f),
myString_ ("StringValue")
{
}
MyObject::~MyObject ()
{
}
void MyObject::RegisterObject (Urho3D::Context *context)
{
context->RegisterFactory <MyObject> ();
URHO3D_MIXED_ACCESSOR_VARIANT_VECTOR_STRUCTURE_ATTRIBUTE ("My Array", GetMyArrayAttribute, SetMyArrayAttribute, Urho3D::VariantVector, Urho3D::Variant::emptyVariantVector, myArrayStructureElementsNames, Urho3D::AM_DEFAULT);
URHO3D_ACCESSOR_ATTRIBUTE ("My float", GetMyFloat, SetMyFloat, float, 500.0f, Urho3D::AM_DEFAULT);
URHO3D_MIXED_ACCESSOR_ATTRIBUTE ("My String", GetMyString, SetMyString, Urho3D::String, Urho3D::String ("StringValue"), Urho3D::AM_DEFAULT);
}
Urho3D::PODVector <Urho3D::StringHash> MyObject::GetMyArray () const
{
return myArray_;
}
void MyObject::SetMyArray (const Urho3D::PODVector <Urho3D::StringHash> & myArray)
{
myArray_ = myArray;
}
Urho3D::VariantVector MyObject::GetMyArrayAttribute () const
{
Urho3D::VariantVector variantVector;
variantVector.Push (Urho3D::Variant (myArray_.Size ()));
for (int index = 0; index < myArray_.Size (); index++)
{
variantVector.Push (Urho3D::Variant (myArray_.At (index)));
}
return variantVector;
}
void MyObject::SetMyArrayAttribute (const Urho3D::VariantVector &myArray)
{
myArray_.Clear ();
if (!myArray.Empty ())
{
int requestedSize = myArray.At (0).GetInt ();
if (requestedSize > 0)
{
for (int index = 0; index < requestedSize; index++)
{
if (index + 1 < myArray.Size ())
{
myArray_.Push (myArray.At (index + 1).GetStringHash ());
}
else
{
myArray_.Push (Urho3D::StringHash ());
}
}
}
}
}
float MyObject::GetMyFloat () const
{
return myFloat_;
}
void MyObject::SetMyFloat (float myFloat)
{
myFloat_ = myFloat;
}
Urho3D::String MyObject::GetMyString () const
{
return myString_;
}
void MyObject::SetMyString (const Urho3D::String & myString)
{
myString_ = myString;
}
#include <Urho3D/ThirdParty/AngelScript/angelscript.h>
#include <Urho3D/AngelScript/APITemplates.h>
Urho3D::CScriptArray *MyObject_GetMyArray (MyObject *object)
{
Urho3D::PODVector <Urho3D::StringHash> array = object->GetMyArray ();
return Urho3D::VectorToArray <Urho3D::StringHash> (array, "Array <StringHash>");
}
void MyObject_SetMyArray (MyObject *object, Urho3D::CScriptArray *array)
{
object->SetMyArray (Urho3D::ArrayToPODVector <Urho3D::StringHash> (array));
}
void BindMyObject (asIScriptEngine *engine)
{
Urho3D::RegisterObject <MyObject> (engine, "MyObject");
engine->RegisterObjectMethod ("MyObject", "Array <StringHash> @get_myArray () const", asFUNCTION (MyObject_GetMyArray), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod ("MyObject", "void set_myArray (Array <StringHash> @myArray)", asFUNCTION (MyObject_SetMyArray), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod ("MyObject", "float get_myFloat () const", asMETHOD (MyObject, GetMyFloat), asCALL_THISCALL);
engine->RegisterObjectMethod ("MyObject", "void set_myFloat (float myFloat)", asMETHOD (MyObject, SetMyFloat), asCALL_THISCALL);
engine->RegisterObjectMethod ("MyObject", "String get_myString () const", asMETHOD (MyObject, GetMyString), asCALL_THISCALL);
engine->RegisterObjectMethod ("MyObject", "void set_myString (String myString)", asMETHOD (MyObject, SetMyString), asCALL_THISCALL);
}