From 0355ff651ea76684b1d725eb07e2e4e12ae2031d Mon Sep 17 00:00:00 2001 From: turanszkij Date: Thu, 6 Aug 2015 19:19:40 +0200 Subject: [PATCH] lua binders updated + renderable2dcomponent binding --- WickedEngine/MainComponent_BindLua.cpp | 30 +++++++-- WickedEngine/MainComponent_BindLua.h | 1 + WickedEngine/Renderable2DComponent.cpp | 3 + .../Renderable2DComponent_BindLua.cpp | 62 +++++++++++++++++++ WickedEngine/Renderable2DComponent_BindLua.h | 24 +++++++ .../Renderable3DComponent_BindLua.cpp | 5 ++ WickedEngine/WickedEngine.vcxproj | 2 + WickedEngine/WickedEngine.vcxproj.filters | 6 ++ WickedEngine/wiResourceManager_BindLua.cpp | 1 - 9 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 WickedEngine/Renderable2DComponent_BindLua.cpp create mode 100644 WickedEngine/Renderable2DComponent_BindLua.h diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp index 355e3b778..08463fe43 100644 --- a/WickedEngine/MainComponent_BindLua.cpp +++ b/WickedEngine/MainComponent_BindLua.cpp @@ -1,9 +1,12 @@ #include "MainComponent_BindLua.h" #include "Renderable3DComponent_BindLua.h" +#include "Renderable2DComponent_BindLua.h" +#include "wiResourceManager_BindLua.h" const char MainComponent_BindLua::className[] = "MainComponent"; Luna::FunctionType MainComponent_BindLua::methods[] = { + lunamethod(MainComponent_BindLua, GetContent), lunamethod(MainComponent_BindLua, GetActiveComponent), lunamethod(MainComponent_BindLua, SetActiveComponent), lunamethod(MainComponent_BindLua, SetFrameSkip), @@ -26,16 +29,35 @@ MainComponent_BindLua::~MainComponent_BindLua() { } +int MainComponent_BindLua::GetContent(lua_State *L) +{ + if (component == nullptr) + { + wiLua::SError(L, "GetContent() component is empty!"); + return 0; + } + Luna::push(L, new wiResourceManager_BindLua(&component->Content)); + return 1; +} int MainComponent_BindLua::GetActiveComponent(lua_State *L) { - Renderable3DComponent* comp = dynamic_cast(component->getActiveComponent()); - if (comp != nullptr) + //return 3d component if the active one is of that type + Renderable3DComponent* comp3D = dynamic_cast(component->getActiveComponent()); + if (comp3D != nullptr) { - Luna::push(L, new Renderable3DComponent_BindLua(comp)); + Luna::push(L, new Renderable3DComponent_BindLua(comp3D)); return 1; } - wiLua::SError(L, "GetActiveComponent() Warning: type of active component not registered with lua!"); + //return 2d component if the active one is of that type + Renderable2DComponent* comp2D = dynamic_cast(component->getActiveComponent()); + if (comp2D != nullptr) + { + Luna::push(L, new Renderable2DComponent_BindLua(comp2D)); + return 1; + } + + wiLua::SError(L, "GetActiveComponent() Warning: type of active component not registered!"); return 0; } int MainComponent_BindLua::SetActiveComponent(lua_State *L) diff --git a/WickedEngine/MainComponent_BindLua.h b/WickedEngine/MainComponent_BindLua.h index 24bfa4bb3..339d1209e 100644 --- a/WickedEngine/MainComponent_BindLua.h +++ b/WickedEngine/MainComponent_BindLua.h @@ -16,6 +16,7 @@ public: MainComponent_BindLua(lua_State *L); ~MainComponent_BindLua(); + int GetContent(lua_State *L); int GetActiveComponent(lua_State *L); int SetActiveComponent(lua_State *L); int SetFrameSkip(lua_State *L); diff --git a/WickedEngine/Renderable2DComponent.cpp b/WickedEngine/Renderable2DComponent.cpp index 164ddfbc3..4627ff159 100644 --- a/WickedEngine/Renderable2DComponent.cpp +++ b/WickedEngine/Renderable2DComponent.cpp @@ -1,11 +1,14 @@ #include "Renderable2DComponent.h" #include "wiResourceManager.h" #include "wiSprite.h" +#include "Renderable2DComponent_BindLua.h" Renderable2DComponent::Renderable2DComponent() { setSpriteSpeed(1.f); m_sprites.clear(); + + Renderable2DComponent_BindLua::Bind(); } diff --git a/WickedEngine/Renderable2DComponent_BindLua.cpp b/WickedEngine/Renderable2DComponent_BindLua.cpp new file mode 100644 index 000000000..e6a9d0d7e --- /dev/null +++ b/WickedEngine/Renderable2DComponent_BindLua.cpp @@ -0,0 +1,62 @@ +#include "Renderable2DComponent_BindLua.h" +#include "wiResourceManager_BindLua.h" + +const char Renderable2DComponent_BindLua::className[] = "Renderable2DComponent"; + +Luna::FunctionType Renderable2DComponent_BindLua::methods[] = { + lunamethod(Renderable2DComponent_BindLua, GetContent), + lunamethod(Renderable2DComponent_BindLua, AddSprite), + { NULL, NULL } +}; +Luna::PropertyType Renderable2DComponent_BindLua::properties[] = { + { NULL, NULL } +}; + +Renderable2DComponent_BindLua::Renderable2DComponent_BindLua(Renderable2DComponent* component) :component(component) +{ +} + +Renderable2DComponent_BindLua::Renderable2DComponent_BindLua(lua_State *L) +{ + component = new Renderable2DComponent(); +} + + +Renderable2DComponent_BindLua::~Renderable2DComponent_BindLua() +{ +} + +int Renderable2DComponent_BindLua::GetContent(lua_State *L) +{ + if (component == nullptr) + { + wiLua::SError(L, "GetContent() component is empty!"); + return 0; + } + Luna::push(L, new wiResourceManager_BindLua(&component->Content)); + return 1; +} + +int Renderable2DComponent_BindLua::AddSprite(lua_State *L) +{ + int argc = wiLua::SGetArgCount(L); + if (argc > 1) + { + //TODO + } + else + { + wiLua::SError(L, "AddSprite(Sprite sprite) not enough arguments!"); + } + return 0; +} + +void Renderable2DComponent_BindLua::Bind() +{ + static bool initialized = false; + if (!initialized) + { + initialized = true; + Luna::Register(wiLua::GetGlobal()->GetLuaState()); + } +} \ No newline at end of file diff --git a/WickedEngine/Renderable2DComponent_BindLua.h b/WickedEngine/Renderable2DComponent_BindLua.h new file mode 100644 index 000000000..25852eb4f --- /dev/null +++ b/WickedEngine/Renderable2DComponent_BindLua.h @@ -0,0 +1,24 @@ +#pragma once +#include "wiLua.h" +#include "wiLuna.h" +#include "Renderable2DComponent.h" + +class Renderable2DComponent_BindLua +{ +private: + Renderable2DComponent* component; +public: + static const char className[]; + static Luna::FunctionType methods[]; + static Luna::PropertyType properties[]; + + Renderable2DComponent_BindLua(Renderable2DComponent* component = nullptr); + Renderable2DComponent_BindLua(lua_State *L); + ~Renderable2DComponent_BindLua(); + + int GetContent(lua_State *L); + int AddSprite(lua_State *L); + + static void Bind(); +}; + diff --git a/WickedEngine/Renderable3DComponent_BindLua.cpp b/WickedEngine/Renderable3DComponent_BindLua.cpp index 9be986e34..e22edfbf7 100644 --- a/WickedEngine/Renderable3DComponent_BindLua.cpp +++ b/WickedEngine/Renderable3DComponent_BindLua.cpp @@ -26,6 +26,11 @@ Renderable3DComponent_BindLua::~Renderable3DComponent_BindLua() int Renderable3DComponent_BindLua::GetContent(lua_State *L) { + if (component == nullptr) + { + wiLua::SError(L, "GetContent() component is empty!"); + return 0; + } Luna::push(L, new wiResourceManager_BindLua(&component->Content)); return 1; } diff --git a/WickedEngine/WickedEngine.vcxproj b/WickedEngine/WickedEngine.vcxproj index 8ba06d10a..20d264ba4 100644 --- a/WickedEngine/WickedEngine.vcxproj +++ b/WickedEngine/WickedEngine.vcxproj @@ -212,6 +212,7 @@ + @@ -411,6 +412,7 @@ + diff --git a/WickedEngine/WickedEngine.vcxproj.filters b/WickedEngine/WickedEngine.vcxproj.filters index c8cdf9e3f..1f737b563 100644 --- a/WickedEngine/WickedEngine.vcxproj.filters +++ b/WickedEngine/WickedEngine.vcxproj.filters @@ -752,6 +752,9 @@ ScriptBinders + + ScriptBinders + @@ -1675,6 +1678,9 @@ ScriptBinders + + ScriptBinders + diff --git a/WickedEngine/wiResourceManager_BindLua.cpp b/WickedEngine/wiResourceManager_BindLua.cpp index f6ca21ce4..317caacb4 100644 --- a/WickedEngine/wiResourceManager_BindLua.cpp +++ b/WickedEngine/wiResourceManager_BindLua.cpp @@ -103,7 +103,6 @@ int wiResourceManager_BindLua::Del(lua_State *L) int wiResourceManager_BindLua::List(lua_State *L) { stringstream ss(""); - ss << "Resources of: " << wiLua::SGetString(L, 1) << endl; for (auto& x : resources->resources) { ss << x.first << endl;