Shader load functions argument fix. File drop and change directory.
This commit is contained in:
34
API.md
34
API.md
@@ -1120,7 +1120,8 @@ End scissor mode
|
||||
|
||||
> shader = RL_LoadShader( string vsFileName, string fsFileName )
|
||||
|
||||
Load shader from files and bind default locations
|
||||
Load shader from files and bind default locations.
|
||||
NOTE: Set nil if no shader
|
||||
|
||||
- Failure return -1
|
||||
- Success return int
|
||||
@@ -1130,6 +1131,7 @@ Load shader from files and bind default locations
|
||||
> shader = RL_LoadShaderFromMemory( string vsCode, string fsCode )
|
||||
|
||||
Load shader from code strings and bind default locations
|
||||
NOTE: Set nil if no shader
|
||||
|
||||
- Failure return -1
|
||||
- Success return int
|
||||
@@ -1577,7 +1579,7 @@ Get full path for a given fileName with path ( Uses static string )
|
||||
|
||||
---
|
||||
|
||||
> filePath = RL_GetPrevDirectoryPath( string dirPath )
|
||||
> directory = RL_GetPrevDirectoryPath( string dirPath )
|
||||
|
||||
Get previous directory path for a given path ( Uses static string )
|
||||
|
||||
@@ -1586,11 +1588,10 @@ Get previous directory path for a given path ( Uses static string )
|
||||
|
||||
---
|
||||
|
||||
> filePath = RL_GetWorkingDirectory()
|
||||
> directory = RL_GetWorkingDirectory()
|
||||
|
||||
Get current working directory ( Uses static string )
|
||||
|
||||
- Failure return false
|
||||
- Success return string
|
||||
|
||||
---
|
||||
@@ -1604,6 +1605,31 @@ Get filenames in a directory path
|
||||
|
||||
---
|
||||
|
||||
> success = RL_ChangeDirectory( string directory )
|
||||
|
||||
Change working directory, return true on success
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
|
||||
---
|
||||
|
||||
> fileDropped = RL_IsFileDropped()
|
||||
|
||||
Check if a file has been dropped into window
|
||||
|
||||
- Success return bool
|
||||
|
||||
---
|
||||
|
||||
> files = RL_GetDroppedFiles()
|
||||
|
||||
Get dropped files names
|
||||
|
||||
- Success return string{}
|
||||
|
||||
---
|
||||
|
||||
> time = RL_GetFileModTime( string fileName )
|
||||
|
||||
Get file modification time ( Last write time )
|
||||
|
||||
@@ -15,7 +15,6 @@ ReiLua is currently in arbitrary version 0.1 and some planned raylib functionali
|
||||
List of some MISSING features that are planned to be included. For specific function, check API.
|
||||
|
||||
* Core
|
||||
* Files drop
|
||||
* VR stereo config functions for VR simulator
|
||||
* Textures
|
||||
* Texture update functions
|
||||
|
||||
5
devnotes
5
devnotes
@@ -2,11 +2,8 @@ Current {
|
||||
}
|
||||
|
||||
Backlog {
|
||||
* Set reguirement for two arguments in Shader load functions.
|
||||
* More and better examples
|
||||
* More and better examples.
|
||||
|
||||
* Core
|
||||
* Files drop
|
||||
* Text
|
||||
* More Font loading/unloading functions
|
||||
* Codepoints
|
||||
|
||||
@@ -13,7 +13,9 @@ function init()
|
||||
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
|
||||
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
|
||||
image = RL_GenImageColor( winSize[1], winSize[2], WHITE )
|
||||
catImage = RL_LoadImage( RL_GetBasePath().."../resources/images/cat.png" )
|
||||
-- Test changing working directory.
|
||||
RL_ChangeDirectory( RL_GetBasePath().."../resources" )
|
||||
catImage = RL_LoadImage( RL_GetWorkingDirectory().."/images/cat.png" )
|
||||
RL_ImageClearBackground( image, { 150, 60, 100 } )
|
||||
RL_ImageDrawPixel( image, { 32, 32 }, WHITE )
|
||||
RL_ImageDrawLine( image, { 32, 45 }, { 100, 60 }, GREEN )
|
||||
@@ -23,12 +25,10 @@ function init()
|
||||
RL_ImageDraw( image, catImage, { 143, 25, 230, 250 }, { 200, 200, 230, 250 }, WHITE )
|
||||
RL_ImageDrawTextEx( image, 0, "Hello", { 300, 32 }, 48.0, 1.0, WHITE )
|
||||
|
||||
-- catCopy = RL_ImageCopy( catImage )
|
||||
local src = { 80, 70, 96, 96 }
|
||||
catCopy = RL_ImageFromImage( catImage, src )
|
||||
|
||||
RL_ImageDraw( image, catCopy, src, { 600, 200, src[3], src[4] }, WHITE )
|
||||
-- RL_ImageDraw( image, catCopy, src, src, WHITE )
|
||||
|
||||
textImage = RL_ImageText( 0, "Cat", 10, 4, WHITE )
|
||||
local imageSize = RL_GetImageSize( textImage )
|
||||
|
||||
@@ -81,6 +81,9 @@ int lcoreGetDirectoryPath( lua_State *L );
|
||||
int lcoreGetPrevDirectoryPath( lua_State *L );
|
||||
int lcoreGetWorkingDirectory( lua_State *L );
|
||||
int lcoreGetDirectoryFiles( lua_State *L );
|
||||
int lcoreChangeDirectory( lua_State *L );
|
||||
int lcoreIsFileDropped( lua_State *L );
|
||||
int lcoreGetDroppedFiles( lua_State *L );
|
||||
int lcoreGetFileModTime( lua_State *L );
|
||||
/* Camera2D. */
|
||||
int lcoreCreateCamera2D( lua_State *L );
|
||||
|
||||
140
src/core.c
140
src/core.c
@@ -849,31 +849,34 @@ int lcoreEndScissorMode( lua_State *L ) {
|
||||
/*
|
||||
> shader = RL_LoadShader( string vsFileName, string fsFileName )
|
||||
|
||||
Load shader from files and bind default locations
|
||||
Load shader from files and bind default locations.
|
||||
NOTE: Set nil if no shader
|
||||
|
||||
- Failure return -1
|
||||
- Success return int
|
||||
*/
|
||||
int lcoreLoadShader( lua_State *L ) {
|
||||
// if ( !lua_isstring( L, -2 ) || !lua_isstring( L, -1 ) ) {
|
||||
// TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadShader( string vsFileName, string fsFileName )" );
|
||||
// lua_pushinteger( L, -1 );
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
char fsFileName[ STRING_LEN ] = { '\0' };
|
||||
char vsFileName[ STRING_LEN ] = { '\0' };
|
||||
|
||||
if ( lua_isstring( L, -1 ) ) {
|
||||
if ( FileExists( lua_tostring( L, -1 ) ) ) {
|
||||
strcpy( fsFileName, lua_tostring( L, -1 ) );
|
||||
}
|
||||
if ( !( lua_isstring( L, -2 ) || lua_isnil( L, -2 ) ) || !( lua_isstring( L, -1 ) || lua_isnil( L, -1 ) ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadShader( string vsFileName, string fsFileName )" );
|
||||
lua_pushinteger( L, -1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *vsFileName = NULL;
|
||||
char *fsFileName = NULL;
|
||||
|
||||
if ( lua_isstring( L, -2 ) ) {
|
||||
if ( FileExists( lua_tostring( L, -2 ) ) ) {
|
||||
vsFileName = malloc( STRING_LEN * sizeof( char ) );
|
||||
strcpy( vsFileName, lua_tostring( L, -2 ) );
|
||||
}
|
||||
}
|
||||
if ( lua_isstring( L, -1 ) ) {
|
||||
if ( FileExists( lua_tostring( L, -1 ) ) ) {
|
||||
fsFileName = malloc( STRING_LEN * sizeof( char ) );
|
||||
strcpy( fsFileName, lua_tostring( L, -1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
@@ -883,12 +886,17 @@ int lcoreLoadShader( lua_State *L ) {
|
||||
}
|
||||
}
|
||||
state->shaders[i] = malloc( sizeof( Shader ) );
|
||||
// *state->shaders[i] = LoadShader( lua_tostring( L, -2 ), lua_tostring( L, -1 ) );
|
||||
*state->shaders[i] = LoadShader( vsFileName, fsFileName );
|
||||
// *state->shaders[i] = LoadShader( 0, fsFileName );
|
||||
lua_pushinteger( L, i );
|
||||
checkShaderRealloc( i );
|
||||
|
||||
if ( vsFileName != NULL ) {
|
||||
free( vsFileName );
|
||||
}
|
||||
if ( fsFileName != NULL ) {
|
||||
free( fsFileName );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -896,27 +904,34 @@ int lcoreLoadShader( lua_State *L ) {
|
||||
> shader = RL_LoadShaderFromMemory( string vsCode, string fsCode )
|
||||
|
||||
Load shader from code strings and bind default locations
|
||||
NOTE: Set nil if no shader
|
||||
|
||||
- Failure return -1
|
||||
- Success return int
|
||||
*/
|
||||
|
||||
int lcoreLoadShaderFromMemory( lua_State *L ) {
|
||||
// if ( !lua_isstring( L, -2 ) || !lua_isstring( L, -1 ) ) {
|
||||
// TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadShaderFromMemory( string vsCode, string fsCode )" );
|
||||
// lua_pushinteger( L, -1 );
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
char fs[ STRING_LEN ] = { '\0' };
|
||||
char vs[ STRING_LEN ] = { '\0' };
|
||||
|
||||
if ( lua_isstring( L, -1 ) ) {
|
||||
strcpy( fs, lua_tostring( L, -1 ) );
|
||||
if ( !( lua_isstring( L, -2 ) || lua_isnil( L, -2 ) ) || !( lua_isstring( L, -1 ) || lua_isnil( L, -1 ) ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadShaderFromMemory( string vsCode, string fsCode )" );
|
||||
lua_pushinteger( L, -1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *vs = NULL;
|
||||
char *fs = NULL;
|
||||
|
||||
if ( lua_isstring( L, -2 ) ) {
|
||||
size_t vsLen = lua_rawlen( L, -2 );
|
||||
|
||||
vs = malloc( vsLen * sizeof( char ) );
|
||||
strcpy( vs, lua_tostring( L, -2 ) );
|
||||
}
|
||||
if ( lua_isstring( L, -1 ) ) {
|
||||
size_t fsLen = lua_rawlen( L, -1 );
|
||||
|
||||
fs = malloc( fsLen * sizeof( char ) );
|
||||
strcpy( fs, lua_tostring( L, -1 ) );
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
@@ -926,11 +941,17 @@ int lcoreLoadShaderFromMemory( lua_State *L ) {
|
||||
}
|
||||
}
|
||||
state->shaders[i] = malloc( sizeof( Shader ) );
|
||||
// *state->shaders[i] = LoadShaderFromMemory( lua_tostring( L, -2 ), lua_tostring( L, -1 ) );
|
||||
*state->shaders[i] = LoadShaderFromMemory( vs, fs );
|
||||
lua_pushinteger( L, i );
|
||||
checkShaderRealloc( i );
|
||||
|
||||
if ( vs != NULL ) {
|
||||
free( vs );
|
||||
}
|
||||
if ( fs != NULL ) {
|
||||
free( fs );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1932,7 +1953,7 @@ int lcoreGetDirectoryPath( lua_State *L ) {
|
||||
}
|
||||
|
||||
/*
|
||||
> filePath = RL_GetPrevDirectoryPath( string dirPath )
|
||||
> directory = RL_GetPrevDirectoryPath( string dirPath )
|
||||
|
||||
Get previous directory path for a given path ( Uses static string )
|
||||
|
||||
@@ -1950,19 +1971,13 @@ int lcoreGetPrevDirectoryPath( lua_State *L ) {
|
||||
}
|
||||
|
||||
/*
|
||||
> filePath = RL_GetWorkingDirectory()
|
||||
> directory = RL_GetWorkingDirectory()
|
||||
|
||||
Get current working directory ( Uses static string )
|
||||
|
||||
- Failure return false
|
||||
- Success return string
|
||||
*/
|
||||
int lcoreGetWorkingDirectory( lua_State *L ) {
|
||||
if ( !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetWorkingDirectory()" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
lua_pushstring( L, GetWorkingDirectory() );
|
||||
return 1;
|
||||
}
|
||||
@@ -1995,6 +2010,59 @@ int lcoreGetDirectoryFiles( lua_State *L ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> success = RL_ChangeDirectory( string directory )
|
||||
|
||||
Change working directory, return true on success
|
||||
|
||||
- Failure return false
|
||||
- Success return true
|
||||
*/
|
||||
int lcoreChangeDirectory( lua_State *L ) {
|
||||
if ( !lua_isstring( L, -1 ) ) {
|
||||
TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_ChangeDirectory( string directory )" );
|
||||
lua_pushboolean( L, false );
|
||||
return 1;
|
||||
}
|
||||
lua_pushboolean( L, ChangeDirectory( lua_tostring( L, -1 ) ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> fileDropped = RL_IsFileDropped()
|
||||
|
||||
Check if a file has been dropped into window
|
||||
|
||||
- Success return bool
|
||||
*/
|
||||
int lcoreIsFileDropped( lua_State *L ) {
|
||||
lua_pushboolean( L, IsFileDropped() );
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> files = RL_GetDroppedFiles()
|
||||
|
||||
Get dropped files names
|
||||
|
||||
- Success return string{}
|
||||
*/
|
||||
int lcoreGetDroppedFiles( lua_State *L ) {
|
||||
int count = 0;
|
||||
char **files = GetDroppedFiles( &count );
|
||||
|
||||
lua_createtable( L, count, 0 );
|
||||
|
||||
for ( int i = 0; i < count; ++i ) {
|
||||
lua_pushstring( L, files[i] );
|
||||
lua_rawseti( L, -2, i+1 );
|
||||
}
|
||||
|
||||
ClearDroppedFiles();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
> time = RL_GetFileModTime( string fileName )
|
||||
|
||||
|
||||
@@ -552,6 +552,9 @@ void luaRegister() {
|
||||
lua_register( L, "RL_GetPrevDirectoryPath", lcoreGetPrevDirectoryPath );
|
||||
lua_register( L, "RL_GetWorkingDirectory", lcoreGetWorkingDirectory );
|
||||
lua_register( L, "RL_GetDirectoryFiles", lcoreGetDirectoryFiles );
|
||||
lua_register( L, "RL_ChangeDirectory", lcoreChangeDirectory );
|
||||
lua_register( L, "RL_IsFileDropped", lcoreIsFileDropped );
|
||||
lua_register( L, "RL_GetDroppedFiles", lcoreGetDroppedFiles );
|
||||
lua_register( L, "RL_GetFileModTime", lcoreGetFileModTime );
|
||||
/* Camera3D. */
|
||||
lua_register( L, "RL_CreateCamera2D", lcoreCreateCamera2D );
|
||||
|
||||
Reference in New Issue
Block a user