42 lines
957 B
C++
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;
|
||
|
}
|