diff --git a/src/api.h b/src/api.h index dfc242c5..131c1da0 100644 --- a/src/api.h +++ b/src/api.h @@ -47,6 +47,7 @@ extern const luaL_Reg lovrMaterial[]; extern const luaL_Reg lovrMesh[]; extern const luaL_Reg lovrModel[]; extern const luaL_Reg lovrRandomGenerator[]; +extern const luaL_Reg lovrRasterizer[]; extern const luaL_Reg lovrShader[]; extern const luaL_Reg lovrShape[]; extern const luaL_Reg lovrSliderJoint[]; diff --git a/src/api/data.c b/src/api/data.c index 4c90d4b7..97a22e4d 100644 --- a/src/api/data.c +++ b/src/api/data.c @@ -1,22 +1,15 @@ #include "api.h" #include "data/data.h" -#include "data/texture.h" #include "data/audioStream.h" +#include "data/rasterizer.h" +#include "data/texture.h" int l_lovrDataInit(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrData); - luax_registertype(L, "TextureData", lovrTextureData); luax_registertype(L, "AudioStream", lovrAudioStream); - return 1; -} - -int l_lovrDataNewTextureData(lua_State* L) { - Blob* blob = luax_readblob(L, 1, "Texture"); - TextureData* textureData = lovrTextureDataFromBlob(blob); - luax_pushtype(L, TextureData, textureData); - lovrRelease(&blob->ref); - lovrRelease(&textureData->ref); + luax_registertype(L, "Rasterizer", lovrRasterizer); + luax_registertype(L, "TextureData", lovrTextureData); return 1; } @@ -30,8 +23,40 @@ int l_lovrDataNewAudioStream(lua_State* L) { return 1; } +int l_lovrDataNewTextureData(lua_State* L) { + Blob* blob = luax_readblob(L, 1, "Texture"); + TextureData* textureData = lovrTextureDataFromBlob(blob); + luax_pushtype(L, TextureData, textureData); + lovrRelease(&blob->ref); + lovrRelease(&textureData->ref); + return 1; +} + +int l_lovrDataNewRasterizer(lua_State* L) { + Blob* blob = NULL; + float size; + + if (lua_type(L, 1) == LUA_TNUMBER || lua_isnoneornil(L, 1)) { + size = luaL_optnumber(L, 1, 32); + } else { + blob = luax_readblob(L, 1, "Font"); + size = luaL_optnumber(L, 2, 32); + } + + Rasterizer* rasterizer = lovrRasterizerCreate(blob, size); + luax_pushtype(L, Rasterizer, rasterizer); + + if (blob) { + lovrRelease(&blob->ref); + } + + lovrRelease(&rasterizer->ref); + return 1; +} + const luaL_Reg lovrData[] = { { "newAudioStream", l_lovrDataNewAudioStream }, + { "newRasterizer", l_lovrDataNewRasterizer }, { "newTextureData", l_lovrDataNewTextureData }, { NULL, NULL } }; diff --git a/src/api/types/rasterizer.c b/src/api/types/rasterizer.c new file mode 100644 index 00000000..50706909 --- /dev/null +++ b/src/api/types/rasterizer.c @@ -0,0 +1,5 @@ +#include "api.h" + +const luaL_Reg lovrRasterizer[] = { + { NULL, NULL } +};