LuaYard/Texture.cpp
Kiritow bc189b4951 完整重构
分离各SDL类的包装代码.
事件分发处理全部转移至Lua Init层. C层只提供获取事件的方法.
这样有助于提高性能,以及今后Coroutine scheduler的添加.
2019-08-25 00:09:28 +08:00

42 lines
957 B
C++

#include "Texture.h"
#include "LuaHelper.h"
#include <iostream>
using namespace std;
inline Texture::Texture(const std::shared_ptr<SDL_Renderer>& exrnd, SDL_Texture* t) : rnd(exrnd), text(t, SDL_DestroyTexture)
{
SDL_QueryTexture(t, NULL, NULL, &w, &h);
}
int Texture::create(lua_State* L, const std::shared_ptr<SDL_Renderer>& rnd, SDL_Texture* t)
{
cout << "In Texture::create" << endl;
auto p = new (lua_newuserdata(L, sizeof(Texture))) Texture(rnd, t);
// Metatable
if (luaL_newmetatable(L, "texture"))
{
// Type
lua_pushstring(L, "texture");
lua_setfield(L, -2, "type");
// GC
lua_pushcfunction(L, close);
lua_setfield(L, -2, "__gc");
// Fields
lua_newtable(L);
setfn(close, "close");
lua_setfield(L, -2, "__index");
}
lua_setmetatable(L, -2);
return 1;
}
inline int Texture::close(lua_State* L)
{
cout << "In Texture::close" << endl;
auto p = (Texture*)luaL_checkudata(L, 1, "texture");
p->~Texture();
return 0;
}