1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Renamed item.fileSize to item.size in fs.list() return value, enabled 3D in the editor, added a lot of missing documentation

For the return values, I followed this rule: if the fuction returns true on success, it should return false, error on error; for every other case it should return nil, error on error.

Also, who doesn't want to edit code in 3D ? The line depth depends on the indentation level.
This commit is contained in:
Reuh 2016-04-22 13:42:59 +02:00
parent 2b7d37304d
commit 358b68c643
13 changed files with 143 additions and 72 deletions

View file

@ -43,7 +43,9 @@ Load a texture from a file. Supported formats: PNG, JPEG, BMP.
@tparam string path path to the image file
@tparam[opt=PLACE_RAM] number place where to put the loaded texture
@tparam[opt=auto] number type type of the image
@treturn texture the loaded texture object
@treturn[1] texture the loaded texture object
@treturn[2] nil in case of error
@treturn[2] string error message
*/
static int texture_load(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
@ -272,7 +274,7 @@ Save a texture to a file.
@tparam string filename path to the file to save the texture to
@tparam[opt=TYPE_PNG] number type type of the image to save. Can be TYPE_PNG or TYPE_BMP
@treturn[1] boolean true on success
@treturn[2] nil
@treturn[2] boolean `false` in case of error
@treturn[2] string error message
*/
static int texture_save(lua_State *L) {
@ -284,7 +286,7 @@ static int texture_save(lua_State *L) {
if (type == 0) { // PNG
FILE* file = fopen(path, "wb");
if (file == NULL) {
lua_pushnil(L);
lua_pushboolean(L, false);
lua_pushstring(L, "Can open file");
return 2;
}
@ -317,7 +319,7 @@ static int texture_save(lua_State *L) {
} else if (type == 2) { // BMP
u32* buff = malloc(texture->texture->width * texture->texture->height * 4);
if (buff == NULL) {
lua_pushnil(L);
lua_pushboolean(L, false);
lua_pushstring(L, "Failed to allocate buffer");
return 2;
}
@ -330,13 +332,13 @@ static int texture_save(lua_State *L) {
free(buff);
} else {
lua_pushnil(L);
lua_pushboolean(L, false);
lua_pushstring(L, "Not a valid type");
return 2;
}
if (result == 0) {
lua_pushnil(L);
lua_pushboolean(L, false);
lua_pushstring(L, "Failed to save the texture");
return 2;
}