Image export functions.

This commit is contained in:
jussi
2022-03-24 17:10:35 +02:00
parent 26a11a4b7f
commit 3aa949f3f5
5 changed files with 74 additions and 2 deletions

View File

@@ -203,6 +203,56 @@ int ltexturesUnloadImage( lua_State *L ) {
return 1;
}
/*
> success = RL_ExportImage( Image image, string fileName )
Export image data to file, returns true on success
- Failure return nil
- Success return bool
*/
int ltexturesExportImage( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ExportImage( Image image, string fileName )" );
lua_pushnil( L );
return 1;
}
size_t id = lua_tointeger( L, -2 );
if ( !validImage( id ) ) {
lua_pushnil( L );
return 1;
}
lua_pushboolean( L, ExportImage( *state->images[ id ], lua_tostring( L, -1 ) ) );
return 1;
}
/*
> success = RL_ExportImageAsCode( Image image, string fileName )
Export image as code file defining an array of bytes, returns true on success
- Failure return nil
- Success return bool
*/
int ltexturesExportImageAsCode( lua_State *L ) {
if ( !lua_isnumber( L, -2 ) || !lua_isstring( L, -1 ) ) {
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ExportImageAsCode( Image image, string fileName )" );
lua_pushnil( L );
return 1;
}
size_t id = lua_tointeger( L, -2 );
if ( !validImage( id ) ) {
lua_pushnil( L );
return 1;
}
lua_pushboolean( L, ExportImageAsCode( *state->images[ id ], lua_tostring( L, -1 ) ) );
return 1;
}
/*
> texture = RL_LoadTexture( string fileName )