mirror of https://github.com/bjornbytes/lovr.git
Declare data module constructors consistently;
This commit is contained in:
parent
bfb73f0c19
commit
88f367c0e5
|
@ -39,6 +39,31 @@ static int l_lovrDataNewBlob(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrDataNewImage(lua_State* L) {
|
||||
Image* image = NULL;
|
||||
if (lua_type(L, 1) == LUA_TNUMBER) {
|
||||
int width = luaL_checkinteger(L, 1);
|
||||
int height = luaL_checkinteger(L, 2);
|
||||
TextureFormat format = luax_checkenum(L, 3, TextureFormat, "rgba");
|
||||
Blob* blob = lua_isnoneornil(L, 4) ? NULL : luax_checktype(L, 4, Blob);
|
||||
image = lovrImageCreate(width, height, blob, 0x0, format);
|
||||
} else {
|
||||
Image* source = luax_totype(L, 1, Image);
|
||||
if (source) {
|
||||
image = lovrImageCreate(source->width, source->height, source->blob, 0x0, source->format);
|
||||
} else {
|
||||
Blob* blob = luax_readblob(L, 1, "Texture");
|
||||
bool flip = lua_isnoneornil(L, 2) ? true : lua_toboolean(L, 2);
|
||||
image = lovrImageCreateFromBlob(blob, flip);
|
||||
lovrRelease(blob, lovrBlobDestroy);
|
||||
}
|
||||
}
|
||||
|
||||
luax_pushtype(L, Image, image);
|
||||
lovrRelease(image, lovrImageDestroy);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrDataNewModelData(lua_State* L) {
|
||||
Blob* blob = luax_readblob(L, 1, "Model");
|
||||
ModelData* modelData = lovrModelDataCreate(blob, luax_readfile);
|
||||
|
@ -95,31 +120,6 @@ static int l_lovrDataNewSound(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrDataNewImage(lua_State* L) {
|
||||
Image* image = NULL;
|
||||
if (lua_type(L, 1) == LUA_TNUMBER) {
|
||||
int width = luaL_checkinteger(L, 1);
|
||||
int height = luaL_checkinteger(L, 2);
|
||||
TextureFormat format = luax_checkenum(L, 3, TextureFormat, "rgba");
|
||||
Blob* blob = lua_isnoneornil(L, 4) ? NULL : luax_checktype(L, 4, Blob);
|
||||
image = lovrImageCreate(width, height, blob, 0x0, format);
|
||||
} else {
|
||||
Image* source = luax_totype(L, 1, Image);
|
||||
if (source) {
|
||||
image = lovrImageCreate(source->width, source->height, source->blob, 0x0, source->format);
|
||||
} else {
|
||||
Blob* blob = luax_readblob(L, 1, "Texture");
|
||||
bool flip = lua_isnoneornil(L, 2) ? true : lua_toboolean(L, 2);
|
||||
image = lovrImageCreateFromBlob(blob, flip);
|
||||
lovrRelease(blob, lovrBlobDestroy);
|
||||
}
|
||||
}
|
||||
|
||||
luax_pushtype(L, Image, image);
|
||||
lovrRelease(image, lovrImageDestroy);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg lovrData[] = {
|
||||
{ "newBlob", l_lovrDataNewBlob },
|
||||
{ "newImage", l_lovrDataNewImage },
|
||||
|
|
Loading…
Reference in New Issue