updated lua bindings

This commit is contained in:
turanszkij
2015-08-18 22:48:47 +02:00
parent 9d2d82b128
commit 773c3f9c59
6 changed files with 254 additions and 5 deletions
+154 -2
View File
@@ -4,14 +4,152 @@ namespace wiLoader_BindLua
{
void Bind()
{
Node_BindLua::Bind();
Transform_BindLua::Bind();
Object_BindLua::Bind();
Armature_BindLua::Bind();
}
}
const char Node_BindLua::className[] = "Node";
Luna<Node_BindLua>::FunctionType Node_BindLua::methods[] = {
lunamethod(Node_BindLua, GetName),
lunamethod(Node_BindLua, SetName),
{ NULL, NULL }
};
Luna<Node_BindLua>::PropertyType Node_BindLua::properties[] = {
{ NULL, NULL }
};
Node_BindLua::Node_BindLua(Node* node)
{
node = node;
this->node = node;
}
Node_BindLua::Node_BindLua(lua_State *L)
{
node = new Node();
}
Node_BindLua::~Node_BindLua()
{
}
int Node_BindLua::GetName(lua_State* L)
{
if (node == nullptr)
{
wiLua::SError(L, "GetName() node is null!");
return 0;
}
wiLua::SSetString(L, node->name);
return 1;
}
int Node_BindLua::SetName(lua_State* L)
{
if (node == nullptr)
{
wiLua::SError(L, "SetName(String name) node is null!");
return 0;
}
int argc = wiLua::SGetArgCount(L);
if (argc > 1)
{
node->name = wiLua::SGetString(L, 2);
}
else
{
wiLua::SError(L, "SetName(String name) not enough arguments!");
}
return 0;
}
void Node_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<Node_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
}
}
const char Transform_BindLua::className[] = "Transform";
Luna<Transform_BindLua>::FunctionType Transform_BindLua::methods[] = {
lunamethod(Transform_BindLua, GetName),
lunamethod(Transform_BindLua, SetName),
lunamethod(Transform_BindLua, DoTransform),
lunamethod(Transform_BindLua, AttachTo),
lunamethod(Transform_BindLua, Detach),
lunamethod(Transform_BindLua, ApplyTransform),
{ NULL, NULL }
};
Luna<Transform_BindLua>::PropertyType Transform_BindLua::properties[] = {
{ NULL, NULL }
};
Transform_BindLua::Transform_BindLua(Transform* transform)
{
node = transform;
this->transform = transform;
}
Transform_BindLua::Transform_BindLua(lua_State *L)
{
transform = new Transform();
}
Transform_BindLua::~Transform_BindLua()
{
}
int Transform_BindLua::DoTransform(lua_State* L)
{
return 0;
}
int Transform_BindLua::AttachTo(lua_State* L)
{
return 0;
}
int Transform_BindLua::Detach(lua_State* L)
{
return 0;
}
int Transform_BindLua::ApplyTransform(lua_State* L)
{
return 0;
}
void Transform_BindLua::Bind()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
Luna<Transform_BindLua>::Register(wiLua::GetGlobal()->GetLuaState());
}
}
const char Object_BindLua::className[] = "Object";
Luna<Object_BindLua>::FunctionType Object_BindLua::methods[] = {
lunamethod(Object_BindLua, GetName),
lunamethod(Object_BindLua, SetName),
lunamethod(Object_BindLua, DoTransform),
lunamethod(Object_BindLua, AttachTo),
lunamethod(Object_BindLua, Detach),
lunamethod(Object_BindLua, ApplyTransform),
lunamethod(Object_BindLua, SetTransparency),
lunamethod(Object_BindLua, GetTransparency),
lunamethod(Object_BindLua, SetColor),
@@ -22,11 +160,14 @@ Luna<Object_BindLua>::PropertyType Object_BindLua::properties[] = {
{ NULL, NULL }
};
Object_BindLua::Object_BindLua(Object* object) :object(object)
Object_BindLua::Object_BindLua(Object* object)
{
node = object;
this->object = object;
}
Object_BindLua::Object_BindLua(lua_State *L)
{
node = nullptr;
object = nullptr;
}
Object_BindLua::~Object_BindLua()
@@ -106,6 +247,14 @@ void Object_BindLua::Bind()
const char Armature_BindLua::className[] = "Armature";
Luna<Armature_BindLua>::FunctionType Armature_BindLua::methods[] = {
lunamethod(Armature_BindLua, GetName),
lunamethod(Armature_BindLua, SetName),
lunamethod(Armature_BindLua, DoTransform),
lunamethod(Armature_BindLua, AttachTo),
lunamethod(Armature_BindLua, Detach),
lunamethod(Armature_BindLua, ApplyTransform),
lunamethod(Armature_BindLua, GetActions),
lunamethod(Armature_BindLua, GetBones),
lunamethod(Armature_BindLua, ChangeAction),
@@ -115,11 +264,14 @@ Luna<Armature_BindLua>::PropertyType Armature_BindLua::properties[] = {
{ NULL, NULL }
};
Armature_BindLua::Armature_BindLua(Armature* armature) :armature(armature)
Armature_BindLua::Armature_BindLua(Armature* armature)
{
node = armature;
this->armature = armature;
}
Armature_BindLua::Armature_BindLua(lua_State *L)
{
node = nullptr;
armature = nullptr;
}
Armature_BindLua::~Armature_BindLua()
+42 -2
View File
@@ -8,7 +8,47 @@ namespace wiLoader_BindLua
void Bind();
}
class Object_BindLua
class Node_BindLua
{
public:
Node* node;
static const char className[];
static Luna<Node_BindLua>::FunctionType methods[];
static Luna<Node_BindLua>::PropertyType properties[];
Node_BindLua(Node* node = nullptr);
Node_BindLua(lua_State *L);
~Node_BindLua();
int GetName(lua_State* L);
int SetName(lua_State* L);
static void Bind();
};
class Transform_BindLua : public Node_BindLua
{
public:
Transform* transform;
static const char className[];
static Luna<Transform_BindLua>::FunctionType methods[];
static Luna<Transform_BindLua>::PropertyType properties[];
Transform_BindLua(Transform* transform = nullptr);
Transform_BindLua(lua_State *L);
~Transform_BindLua();
int DoTransform(lua_State* L);
int AttachTo(lua_State* L);
int Detach(lua_State* L);
int ApplyTransform(lua_State* L);
static void Bind();
};
class Object_BindLua : public Transform_BindLua
{
public:
Object* object;
@@ -29,7 +69,7 @@ public:
static void Bind();
};
class Armature_BindLua
class Armature_BindLua : public Transform_BindLua
{
public:
Armature* armature;
+9
View File
@@ -1568,6 +1568,15 @@ void wiRenderer::SetUpStates()
}
Transform* wiRenderer::getTransformByName(const string& get)
{
auto transf = transforms.find(get);
if (transf != transforms.end())
{
return transf->second;
}
return nullptr;
}
Armature* wiRenderer::getArmatureByName(const string& get)
{
for(Armature* armature : armatures)
+1
View File
@@ -393,6 +393,7 @@ public:
static TextureView GetNoiseTexture(){ return noiseTex; }
static Transform* getTransformByName(const string& name);
static Armature* getArmatureByName(const string& get);
static int getActionByName(Armature* armature, const string& get);
static int getBoneByName(Armature* armature, const string& get);
+46 -1
View File
@@ -13,6 +13,8 @@ namespace wiRenderer_BindLua
if (!initialized)
{
initialized = true;
wiLua::GetGlobal()->RegisterFunc("GetTransforms", GetTransforms);
wiLua::GetGlobal()->RegisterFunc("GetTransform", GetTransform);
wiLua::GetGlobal()->RegisterFunc("GetArmatures", GetArmatures);
wiLua::GetGlobal()->RegisterFunc("GetArmature", GetArmature);
wiLua::GetGlobal()->RegisterFunc("GetObjects", GetObjects);
@@ -34,6 +36,49 @@ namespace wiRenderer_BindLua
}
}
int GetTransforms(lua_State* L)
{
stringstream ss("");
for (auto& x : wiRenderer::transforms)
{
ss << x.first << endl;
}
wiLua::SSetString(L, ss.str());
return 1;
}
int GetTransform(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
string name = wiLua::SGetString(L, 1);
Transform* transform = wiRenderer::getTransformByName(name);
if (transform != nullptr)
{
Object* object = dynamic_cast<Object*>(transform);
if (object != nullptr)
{
Luna<Object_BindLua>::push(L, new Object_BindLua(object));
return 1;
}
Armature* armature = dynamic_cast<Armature*>(transform);
if (armature != nullptr)
{
Luna<Armature_BindLua>::push(L, new Armature_BindLua(armature));
return 1;
}
Luna<Transform_BindLua>::push(L, new Transform_BindLua(transform));
return 1;
}
else
{
wiLua::SError(L, "GetTransform(String name) transform not found!");
return 0;
}
}
return 0;
}
int GetArmatures(lua_State* L)
{
stringstream ss("");
@@ -58,7 +103,7 @@ namespace wiRenderer_BindLua
}
else
{
wiLua::SError(L, "GetArmature(String name) object not found!");
wiLua::SError(L, "GetArmature(String name) armature not found!");
return 0;
}
}
+2
View File
@@ -6,6 +6,8 @@ namespace wiRenderer_BindLua
void Bind();
int GetTransforms(lua_State* L);
int GetTransform(lua_State* L);
int GetArmatures(lua_State* L);
int GetArmature(lua_State* L);
int GetObjects(lua_State* L);