lovr/src/api/data.c

38 lines
1.0 KiB
C
Raw Normal View History

2018-01-16 07:13:26 +00:00
#include "api.h"
#include "data/data.h"
2018-01-21 21:26:00 +00:00
#include "data/texture.h"
#include "data/audioStream.h"
2018-01-16 07:13:26 +00:00
int l_lovrDataInit(lua_State* L) {
lua_newtable(L);
luaL_register(L, NULL, lovrData);
2018-01-21 05:33:09 +00:00
luax_registertype(L, "TextureData", lovrTextureData);
2018-01-21 21:26:00 +00:00
luax_registertype(L, "AudioStream", lovrAudioStream);
2018-01-21 05:33:09 +00:00
return 1;
}
int l_lovrDataNewTextureData(lua_State* L) {
Blob* blob = luax_readblob(L, 1, "Texture");
TextureData* textureData = lovrTextureDataFromBlob(blob);
2018-01-22 16:08:47 +00:00
luax_pushtype(L, TextureData, textureData);
2018-01-21 05:33:09 +00:00
lovrRelease(&blob->ref);
lovrRelease(&textureData->ref);
2018-01-16 07:13:26 +00:00
return 1;
}
2018-01-21 21:26:00 +00:00
int l_lovrDataNewAudioStream(lua_State* L) {
Blob* blob = luax_readblob(L, 1, "Sound");
size_t bufferSize = luaL_optinteger(L, 2, 4096);
AudioStream* stream = lovrAudioStreamCreate(blob, bufferSize);
2018-01-22 16:08:47 +00:00
luax_pushtype(L, AudioStream, stream);
2018-01-21 21:26:00 +00:00
lovrRelease(&blob->ref);
lovrRelease(&stream->ref);
return 1;
}
2018-01-16 07:13:26 +00:00
const luaL_Reg lovrData[] = {
2018-01-21 21:26:00 +00:00
{ "newAudioStream", l_lovrDataNewAudioStream },
2018-01-21 05:33:09 +00:00
{ "newTextureData", l_lovrDataNewTextureData },
2018-01-16 07:13:26 +00:00
{ NULL, NULL }
};