From e056446750bff6db15842aea662f18a322052d8c Mon Sep 17 00:00:00 2001 From: jussi Date: Thu, 9 Nov 2023 21:24:58 +0200 Subject: Organized core functions. --- src/core.c | 1648 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 836 insertions(+), 812 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index a32b226..05af7c8 100644 --- a/src/core.c +++ b/src/core.c @@ -25,7 +25,7 @@ void unloadBuffer( Buffer *buffer ) { } /* -## Core - Window +## Core - Window-related functions */ /* @@ -467,272 +467,210 @@ int lcoreGetClipboardText( lua_State *L ) { } /* -## Core - Timing +## Core - Cursor-related functions */ /* -> RL.SetTargetFPS( int fps ) +> RL.ShowCursor() -Set target FPS (maximum) +Shows cursor */ -int lcoreSetTargetFPS( lua_State *L ) { - int fps = luaL_checkinteger( L, 1 ); - - SetTargetFPS( fps ); +int lcoreShowCursor( lua_State *L ) { + ShowCursor(); return 0; } /* -> FPS = RL.GetFPS() - -Get current FPS +> RL.HideCursor() -- Success return int +Hides cursor */ -int lcoreGetFPS( lua_State *L ) { - lua_pushinteger( L, GetFPS() ); +int lcoreHideCursor( lua_State *L ) { + HideCursor(); - return 1; + return 0; } /* -> delta = RL.GetFrameTime() +> hidden = RL.IsCursorHidden() -Get time in seconds for last frame drawn (Delta time) +Check if cursor is not visible -- Success return float +- Success return bool */ -int lcoreGetFrameTime( lua_State *L ) { - lua_pushnumber( L, GetFrameTime() ); +int lcoreIsCursorHidden( lua_State *L ) { + lua_pushboolean( L, IsCursorHidden() ); return 1; } /* -> time = RL.GetTime() - -Get elapsed time in seconds since InitWindow() +> RL.EnableCursor() -- Success return float +Enables cursor (unlock cursor) */ -int lcoreGetTime( lua_State *L ) { - lua_pushnumber( L, GetTime() ); +int lcoreEnableCursor( lua_State *L ) { + EnableCursor(); - return 1; + return 0; } /* -## Core - Misc -*/ - -/* -> RL.TakeScreenshot( string fileName ) +> RL.DisableCursor() -Takes a screenshot of current screen (filename extension defines format) +Disables cursor (lock cursor) */ -int lcoreTakeScreenshot( lua_State *L ) { - TakeScreenshot( luaL_checkstring( L, 1 ) ); +int lcoreDisableCursor( lua_State *L ) { + DisableCursor(); return 0; } /* -> RL.SetConfigFlags( int flags ) +> onSreen = RL.IsCursorOnScreen() -Setup init configuration flags (view FLAGS) -*/ -int lcoreSetConfigFlags( lua_State *L ) { - unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 ); +Check if cursor is on the screen - SetConfigFlags( flag ); +- Success return bool +*/ +int lcoreIsCursorOnScreen( lua_State *L ) { + lua_pushboolean( L, IsCursorOnScreen() ); - return 0; + return 1; } /* -> RL.TraceLog( int logLevel, string text ) - -Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) +## Core - Drawing-related functions */ -int lcoreTraceLog( lua_State *L ) { - int logLevel = luaL_checkinteger( L, 1 ); - - TraceLog( logLevel, "%s", luaL_checkstring( L, 2 ) ); - - return 0; -} /* -> RL.SetTraceLogLevel( int logLevel ) +> RL.ClearBackground( Color color ) -Set the current threshold (minimum) log level +Set background color (framebuffer clear color) */ -int lcoreSetTraceLogLevel( lua_State *L ) { - int logLevel = luaL_checkinteger( L, 1 ); +int lcoreClearBackground( lua_State *L ) { + Color color = uluaGetColor( L, 1 ); - SetTraceLogLevel( logLevel ); + ClearBackground( color ); return 0; } /* -> RL.SetLogLevelInvalid( int logLevel ) +> RL.BeginDrawing() -Set the log level for bad function calls and invalid data formats. +Setup canvas (framebuffer) to start drawing */ -int lcoreSetLogLevelInvalid( lua_State *L ) { - state->logLevelInvalid = luaL_checkinteger( L, 1 ); +int lcoreBeginDrawing( lua_State *L ) { + BeginDrawing(); return 0; } /* -> logLevel = RL.GetLogLevelInvalid() - -Get the log level for bad function calls and invalid data formats. - -- Success return int -*/ -int lcoreGetLogLevelInvalid( lua_State *L ) { - lua_pushinteger( L, state->logLevelInvalid ); - - return 1; -} - -/* -> RL.OpenURL( string url ) +> RL.EndDrawing() -Open URL with default system browser (If available) +End canvas drawing and swap buffers (double buffering) */ -int lcoreOpenURL( lua_State *L ) { - OpenURL( luaL_checkstring( L, 1 ) ); +int lcoreEndDrawing( lua_State *L ) { + EndDrawing(); return 0; } /* -> enabled = RL.IsGCUnloadEnabled() - -Check if Lua garbage collection is set to unload object data - -- Success return bool -*/ -int lcoreIsGCUnloadEnabled( lua_State *L ) { - lua_pushboolean( L, state->gcUnload ); - - return 1; -} +> RL.BeginMode2D( camera2D camera ) -/* -## Core - Cursor +Begin 2D mode with custom camera (2D) */ +int lcoreBeginMode2D( lua_State *L ) { + Camera2D *camera = uluaGetCamera2D( L, 1 ); -/* -> RL.ShowCursor() - -Shows cursor -*/ -int lcoreShowCursor( lua_State *L ) { - ShowCursor(); + BeginMode2D( *camera ); return 0; } /* -> RL.HideCursor() +> RL.EndMode2D() -Hides cursor +Ends 2D mode with custom camera */ -int lcoreHideCursor( lua_State *L ) { - HideCursor(); +int lcoreEndMode2D( lua_State *L ) { + EndMode2D(); return 0; } /* -> hidden = RL.IsCursorHidden() - -Check if cursor is not visible +> RL.BeginMode3D( camera3D camera ) -- Success return bool +Begin 3D mode with custom camera (3D) */ -int lcoreIsCursorHidden( lua_State *L ) { - lua_pushboolean( L, IsCursorHidden() ); - - return 1; -} - -/* -> RL.EnableCursor() +int lcoreBeginMode3D( lua_State *L ) { + Camera3D *camera = uluaGetCamera3D( L, 1 ); -Enables cursor (unlock cursor) -*/ -int lcoreEnableCursor( lua_State *L ) { - EnableCursor(); + BeginMode3D( *camera ); return 0; } /* -> RL.DisableCursor() +> RL.EndMode3D() -Disables cursor (lock cursor) +Ends 3D mode and returns to default 2D orthographic mode */ -int lcoreDisableCursor( lua_State *L ) { - DisableCursor(); +int lcoreEndMode3D( lua_State *L ) { + EndMode3D(); return 0; } /* -> onSreen = RL.IsCursorOnScreen() - -Check if cursor is on the screen +> RL.BeginTextureMode( RenderTexture target ) -- Success return bool +Begin drawing to render texture */ -int lcoreIsCursorOnScreen( lua_State *L ) { - lua_pushboolean( L, IsCursorOnScreen() ); +int lcoreBeginTextureMode( lua_State *L ) { + RenderTexture *renderTexture = uluaGetRenderTexture( L, 1 ); - return 1; -} + BeginTextureMode( *renderTexture ); -/* -## Core - Drawing -*/ + return 0; +} /* -> RL.ClearBackground( Color color ) +> RL.EndTextureMode() -Set background color (framebuffer clear color) +Ends drawing to render texture */ -int lcoreClearBackground( lua_State *L ) { - Color color = uluaGetColor( L, 1 ); - - ClearBackground( color ); +int lcoreEndTextureMode( lua_State *L ) { + EndTextureMode(); return 0; } /* -> RL.BeginDrawing() +> RL.BeginShaderMode( Shader shader ) -Setup canvas (framebuffer) to start drawing +Begin custom shader drawing */ -int lcoreBeginDrawing( lua_State *L ) { - BeginDrawing(); +int lcoreBeginShaderMode( lua_State *L ) { + Shader *shader = uluaGetShader( L, 1 ); + + BeginShaderMode( *shader ); return 0; } /* -> RL.EndDrawing() +> RL.EndShaderMode() -End canvas drawing and swap buffers (double buffering) +End custom shader drawing (use default shader) */ -int lcoreEndDrawing( lua_State *L ) { - EndDrawing(); +int lcoreEndShaderMode( lua_State *L ) { + EndShaderMode(); return 0; } @@ -786,7 +724,7 @@ int lcoreEndScissorMode( lua_State *L ) { } /* -## Core - Shader +## Core - Shader management functions */ /* @@ -853,30 +791,6 @@ int lcoreIsShaderReady( lua_State *L ) { return 1; } -/* -> RL.BeginShaderMode( Shader shader ) - -Begin custom shader drawing -*/ -int lcoreBeginShaderMode( lua_State *L ) { - Shader *shader = uluaGetShader( L, 1 ); - - BeginShaderMode( *shader ); - - return 0; -} - -/* -> RL.EndShaderMode() - -End custom shader drawing (use default shader) -*/ -int lcoreEndShaderMode( lua_State *L ) { - EndShaderMode(); - - return 0; -} - /* > location = RL.GetShaderLocation( Shader shader, string uniformName ) @@ -1067,942 +981,1215 @@ int lcoreUnloadShader( lua_State *L ) { } /* -## Core - Input-related Keyboard +## Core - Screen-space-related functions */ /* -> pressed = RL.IsKeyPressed( int key ) +> ray = RL.GetMouseRay( Vector2 mousePosition, Camera3D camera ) -Detect if a key has been pressed once +Get a ray trace from mouse position -- Success return bool +- Success return Ray */ -int lcoreIsKeyPressed( lua_State *L ) { - int key = luaL_checkinteger( L, 1 ); +int lcoreGetMouseRay( lua_State *L ) { + Vector2 mousePosition = uluaGetVector2( L, 1 ); + Camera3D *camera = uluaGetCamera3D( L, 2 ); - lua_pushboolean( L, IsKeyPressed( key ) ); + uluaPushRay( L, GetMouseRay( mousePosition, *camera ) ); return 1; } /* -> pressed = RL.IsKeyDown( int key ) +> matrix = RL.GetCameraMatrix( Camera3D camera ) -Detect if a key is being pressed +Get camera transform matrix (view matrix) + +- Success return Matrix +*/ +int lcoreGetCameraMatrix( lua_State *L ) { + Camera3D *camera = uluaGetCamera3D( L, 1 ); + + uluaPushMatrix( L, GetCameraMatrix( *camera ) ); + + return 1; +} + +/* +> matrix = RL.GetCameraMatrix2D( Camera2D camera ) + +Get camera 2d transform matrix + +- Success return Matrix +*/ +int lcoreGetCameraMatrix2D( lua_State *L ) { + Camera2D *camera = uluaGetCamera2D( L, 1 ); + + uluaPushMatrix( L, GetCameraMatrix2D( *camera ) ); + + return 1; +} + +/* +> position = RL.GetWorldToScreen( Vector3 position, Camera3D camera ) + +Get the screen space position for a 3d world space position + +- Success return Vector2 +*/ +int lcoreGetWorldToScreen( lua_State *L ) { + Vector3 position = uluaGetVector3( L, 1 ); + Camera3D *camera = uluaGetCamera3D( L, 2 ); + + uluaPushVector2( L, GetWorldToScreen( position, *camera ) ); + + return 1; +} + +/* +> position = RL.GetWorldToScreenEx( Vector3 position, Camera3D camera, Vector2 size ) + +Get size position for a 3d world space position + +- Success return Vector2 +*/ +int lcoreGetWorldToScreenEx( lua_State *L ) { + Vector3 position = uluaGetVector3( L, 1 ); + Camera3D *camera = uluaGetCamera3D( L, 2 ); + Vector2 size = uluaGetVector2( L, 3 ); + + uluaPushVector2( L, GetWorldToScreenEx( position, *camera, size.x, size.y ) ); + + return 1; +} + +/* +> position = RL.GetWorldToScreen2D( Vector2 position, Camera2D camera ) + +Get the screen space position for a 2d camera world space position + +- Success return Vector2 +*/ +int lcoreGetWorldToScreen2D( lua_State *L ) { + Vector2 position = uluaGetVector2( L, 1 ); + Camera2D *camera = uluaGetCamera2D( L, 2 ); + + uluaPushVector2( L, GetWorldToScreen2D( position, *camera ) ); + + return 1; +} + +/* +> position = RL.GetScreenToWorld2D( Vector2 position, Camera2D camera ) + +Get the world space position for a 2d camera screen space position + +- Success return Vector2 +*/ +int lcoreGetScreenToWorld2D( lua_State *L ) { + Vector2 position = uluaGetVector2( L, 1 ); + Camera2D *camera = uluaGetCamera2D( L, 2 ); + + uluaPushVector2( L, GetScreenToWorld2D( position, *camera ) ); + + return 1; +} + +/* +## Core - Timing-related functions +*/ + +/* +> RL.SetTargetFPS( int fps ) + +Set target FPS (maximum) +*/ +int lcoreSetTargetFPS( lua_State *L ) { + int fps = luaL_checkinteger( L, 1 ); + + SetTargetFPS( fps ); + + return 0; +} + +/* +> FPS = RL.GetFPS() + +Get current FPS + +- Success return int +*/ +int lcoreGetFPS( lua_State *L ) { + lua_pushinteger( L, GetFPS() ); + + return 1; +} + +/* +> delta = RL.GetFrameTime() + +Get time in seconds for last frame drawn (Delta time) + +- Success return float +*/ +int lcoreGetFrameTime( lua_State *L ) { + lua_pushnumber( L, GetFrameTime() ); + + return 1; +} + +/* +> time = RL.GetTime() + +Get elapsed time in seconds since InitWindow() + +- Success return float +*/ +int lcoreGetTime( lua_State *L ) { + lua_pushnumber( L, GetTime() ); + + return 1; +} + +/* +## Core - Misc +*/ + +/* +> RL.TakeScreenshot( string fileName ) + +Takes a screenshot of current screen (filename extension defines format) +*/ +int lcoreTakeScreenshot( lua_State *L ) { + TakeScreenshot( luaL_checkstring( L, 1 ) ); + + return 0; +} + +/* +> RL.SetConfigFlags( int flags ) + +Setup init configuration flags (view FLAGS) +*/ +int lcoreSetConfigFlags( lua_State *L ) { + unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 ); + + SetConfigFlags( flag ); + + return 0; +} + +/* +> RL.TraceLog( int logLevel, string text ) + +Show trace log messages (LOG_DEBUG, LOG_INFO, LOG_WARNING, LOG_ERROR...) +*/ +int lcoreTraceLog( lua_State *L ) { + int logLevel = luaL_checkinteger( L, 1 ); + + TraceLog( logLevel, "%s", luaL_checkstring( L, 2 ) ); + + return 0; +} + +/* +> RL.SetTraceLogLevel( int logLevel ) + +Set the current threshold (minimum) log level +*/ +int lcoreSetTraceLogLevel( lua_State *L ) { + int logLevel = luaL_checkinteger( L, 1 ); + + SetTraceLogLevel( logLevel ); + + return 0; +} + +/* +> RL.SetLogLevelInvalid( int logLevel ) + +Set the log level for bad function calls and invalid data formats. +*/ +int lcoreSetLogLevelInvalid( lua_State *L ) { + state->logLevelInvalid = luaL_checkinteger( L, 1 ); + + return 0; +} + +/* +> logLevel = RL.GetLogLevelInvalid() + +Get the log level for bad function calls and invalid data formats. + +- Success return int +*/ +int lcoreGetLogLevelInvalid( lua_State *L ) { + lua_pushinteger( L, state->logLevelInvalid ); + + return 1; +} + +/* +> RL.OpenURL( string url ) + +Open URL with default system browser (If available) +*/ +int lcoreOpenURL( lua_State *L ) { + OpenURL( luaL_checkstring( L, 1 ) ); + + return 0; +} + +/* +> enabled = RL.IsGCUnloadEnabled() + +Check if Lua garbage collection is set to unload object data + +- Success return bool +*/ +int lcoreIsGCUnloadEnabled( lua_State *L ) { + lua_pushboolean( L, state->gcUnload ); + + return 1; +} + +/* +## Core - Files management functions +*/ + +/* +> path = RL.GetBasePath() + +Return game directory (where main.lua is located) + +- Success return string +*/ +int lcoreGetBasePath( lua_State *L ) { + lua_pushstring( L, state->exePath ); + + return 1; +} + +/* +> fileExists = RL.FileExists( string fileName ) + +Check if file exists + +- Success return bool +*/ +int lcoreFileExists( lua_State *L ) { + lua_pushboolean( L, FileExists( luaL_checkstring( L, 1 ) ) ); + + return 1; +} + +/* +> dirExists = RL.DirectoryExists( string dirPath ) + +Check if a directory path exists + +- Success return bool +*/ +int lcoreDirectoryExists( lua_State *L ) { + lua_pushboolean( L, DirectoryExists( luaL_checkstring( L, 1 ) ) ); + + return 1; +} + +/* +> hasFileExtension = RL.IsFileExtension( string fileName, string ext ) + +Check file extension (Including point: .png, .wav) + +- Success return bool +*/ +int lcoreIsFileExtension( lua_State *L ) { + lua_pushboolean( L, IsFileExtension( luaL_checkstring( L, 1 ), luaL_checkstring( L, 2 ) ) ); + + return 1; +} + +/* +> length = RL.GetFileLength( string fileName ) + +Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h) + +- Success return int +*/ +int lcoreGetFileLength( lua_State *L ) { + lua_pushinteger( L, GetFileLength( luaL_checkstring( L, 1 ) ) ); + + return 1; +} + +/* +> extension = RL.GetFileExtension( string fileName ) + +Get pointer to extension for a filename string (Includes dot: '.png') + +- Success return string +*/ +int lcoreGetFileExtension( lua_State *L ) { + lua_pushstring( L, GetFileExtension( luaL_checkstring( L, 1 ) ) ); + + return 1; +} -- Success return bool -*/ -int lcoreIsKeyDown( lua_State *L ) { - int key = luaL_checkinteger( L, 1 ); +/* +> fileName = RL.GetFileName( string filePath ) - lua_pushboolean( L, IsKeyDown( key ) ); +Get pointer to filename for a path string + +- Success return string +*/ +int lcoreGetFileName( lua_State *L ) { + lua_pushstring( L, GetFileName( luaL_checkstring( L, 1 ) ) ); return 1; } /* -> released = RL.IsKeyReleased( int key ) +> fileName = RL.GetFileNameWithoutExt( string filePath ) -Detect if a key has been released once +Get filename string without extension (Uses static string) -- Success return bool +- Success return string */ -int lcoreIsKeyReleased( lua_State *L ) { - int key = luaL_checkinteger( L, 1 ); - - lua_pushboolean( L, IsKeyReleased( key ) ); +int lcoreGetFileNameWithoutExt( lua_State *L ) { + lua_pushstring( L, GetFileNameWithoutExt( luaL_checkstring( L, 1 ) ) ); return 1; } /* -> released = RL.IsKeyUp( int key ) +> filePath = RL.GetDirectoryPath( string filePath ) -Check if a key is NOT being pressed +Get full path for a given fileName with path (Uses static string) -- Success return bool +- Success return string */ -int lcoreIsKeyUp( lua_State *L ) { - int key = luaL_checkinteger( L, 1 ); - - lua_pushboolean( L, IsKeyUp( key ) ); +int lcoreGetDirectoryPath( lua_State *L ) { + lua_pushstring( L, GetDirectoryPath( luaL_checkstring( L, 1 ) ) ); return 1; } /* -> keycode = RL.GetKeyPressed() +> directory = RL.GetPrevDirectoryPath( string dirPath ) -Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty +Get previous directory path for a given path (Uses static string) -- Success return int +- Success return string */ -int lcoreGetKeyPressed( lua_State *L ) { - lua_pushinteger( L, GetKeyPressed() ); +int lcoreGetPrevDirectoryPath( lua_State *L ) { + lua_pushstring( L, GetPrevDirectoryPath( luaL_checkstring( L, 1 ) ) ); return 1; } /* -> unicode = RL.GetCharPressed() +> directory = RL.GetWorkingDirectory() -Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty +Get current working directory (Uses static string) -- Success return int +- Success return string */ -int lcoreGetCharPressed( lua_State *L ) { - lua_pushinteger( L, GetCharPressed() ); +int lcoreGetWorkingDirectory( lua_State *L ) { + lua_pushstring( L, GetWorkingDirectory() ); return 1; } /* -> RL.SetExitKey( int key ) +> fileNames = RL.LoadDirectoryFiles( string dirPath ) -Set a custom key to exit program (default is ESC) +Load directory filepaths + +- Success return string{} */ -int lcoreSetExitKey( lua_State *L ) { - int key = luaL_checkinteger( L, 1 ); +int lcoreLoadDirectoryFiles( lua_State *L ) { + FilePathList files = LoadDirectoryFiles( luaL_checkstring( L, 1 ) ); - SetExitKey( key ); + lua_createtable( L, files.count, 0 ); - return 0; + for ( int i = 0; i < files.count; ++i ) { + lua_pushstring( L, files.paths[i] ); + lua_rawseti( L, -2, i+1 ); + } + UnloadDirectoryFiles( files ); + + return 1; } /* -> keyName = RL.GetKeyName( int key, int scancode ) - -This function returns the name of the specified printable key, encoded as UTF-8. -This is typically the character that key would produce without any modifier keys, -intended for displaying key bindings to the user. For dead keys, it is typically -the diacritic it would add to a character. - -Do not use this function for text input. You will break text input for many -languages even if it happens to work for yours. +> fileNames = RL.LoadDirectoryFilesEx( string basePath, string filter, bool scanSubdirs ) -If the key is KEY_UNKNOWN, the scancode is used to identify the key, -otherwise the scancode is ignored. If you specify a non-printable key, -or KEY_UNKNOWN and a scancode that maps to a non-printable key, -this function returns nil but does not emit an error. +Load directory filepaths with extension filtering and recursive directory scan -- Success return string or nil +- Success return string{} */ -int lcoreGetKeyName( lua_State *L ) { - int key = luaL_checkinteger( L, 1 ); - int scancode = luaL_checkinteger( L, 2 ); +int lcoreLoadDirectoryFilesEx( lua_State *L ) { + bool scanSubdirs = uluaGetBoolean( L, 3 ); - const char *keyName = glfwGetKeyName( key, scancode ); + FilePathList files = LoadDirectoryFilesEx( luaL_checkstring( L, 1 ), luaL_checkstring( L, 2 ), scanSubdirs ); - if ( keyName != NULL ) { - lua_pushstring( L, keyName ); - } - else { - lua_pushnil( L ); + lua_createtable( L, files.count, 0 ); + + for ( int i = 0; i < files.count; ++i ) { + lua_pushstring( L, files.paths[i] ); + lua_rawseti( L, -2, i+1 ); } + UnloadDirectoryFiles( files ); return 1; } /* -> scancode = RL.GetKeyScancode( int key ) +> success = RL.ChangeDirectory( string directory ) -This function returns the platform-specific scancode of the specified key. -If the key is KEY_UNKNOWN or does not exist on the keyboard this method will return -1. +Change working directory, return true on success -- Success return int +- Success return bool */ -int lcoreGetKeyScancode( lua_State *L ) { - int key = luaL_checkinteger( L, 1 ); - - lua_pushinteger( L, glfwGetKeyScancode( key ) ); +int lcoreChangeDirectory( lua_State *L ) { + lua_pushboolean( L, ChangeDirectory( luaL_checkstring( L, 1 ) ) ); return 1; } /* -## Core - Input-related Gamepad +> isFile = RL.IsPathFile( string path ) + +Check if a given path is a file or a directory + +- Success return bool */ +int lcoreIsPathFile( lua_State *L ) { + lua_pushboolean( L, IsPathFile( luaL_checkstring( L, 1 ) ) ); + + return 1; +} /* -> available = RL.IsGamepadAvailable( int gamepad ) +> iSFileDropped = RL.IsFileDropped() -Detect if a gamepad is available +Check if a file has been dropped into window - Success return bool */ -int lcoreIsGamepadAvailable( lua_State *L ) { - int gamepad = luaL_checkinteger( L, 1 ); - - lua_pushboolean( L, IsGamepadAvailable( gamepad ) ); +int lcoreIsFileDropped( lua_State *L ) { + lua_pushboolean( L, IsFileDropped() ); return 1; } /* -> pressed = RL.IsGamepadButtonPressed( int gamepad, int button ) +> files = RL.LoadDroppedFiles() -Detect if a gamepad button has been pressed once +Load dropped filepaths -- Success return bool +- Success return string{} */ -int lcoreIsGamepadButtonPressed( lua_State *L ) { - int gamepad = luaL_checkinteger( L, 1 ); - int button = luaL_checkinteger( L, 2 ); +int lcoreLoadDroppedFiles( lua_State *L ) { + FilePathList files = LoadDroppedFiles(); - lua_pushboolean( L, IsGamepadButtonPressed( gamepad, button ) ); + lua_createtable( L, files.count, 0 ); + + for ( int i = 0; i < files.count; ++i ) { + lua_pushstring( L, files.paths[i] ); + lua_rawseti( L, -2, i+1 ); + } + UnloadDroppedFiles( files ); return 1; } /* -> pressed = RL.IsGamepadButtonDown( int gamepad, int button ) +> time = RL.GetFileModTime( string fileName ) -Detect if a gamepad button is being pressed +Get file modification time (Last write time) -- Success return bool +- Success return int */ -int lcoreIsGamepadButtonDown( lua_State *L ) { - int gamepad = luaL_checkinteger( L, 1 ); - int button = luaL_checkinteger( L, 2 ); - - lua_pushboolean( L, IsGamepadButtonDown( gamepad, button ) ); +int lcoreGetFileModTime( lua_State *L ) { + lua_pushinteger( L, GetFileModTime( luaL_checkstring( L, 1 ) ) ); return 1; } /* -> released = RL.IsGamepadButtonReleased( int gamepad, int button ) +## Core - Compression/Encoding functionality +*/ -Detect if a gamepad button has been released once +/* +> compData = RL.CompressData( Buffer buffer ) -- Success return bool +Compress data (DEFLATE algorithm) + +- Success return Buffer */ -int lcoreIsGamepadButtonReleased( lua_State *L ) { - int gamepad = luaL_checkinteger( L, 1 ); - int button = luaL_checkinteger( L, 2 ); +int lcoreCompressData( lua_State *L ) { + Buffer *inBuffer = uluaGetBuffer( L, 1 ); + Buffer outBuffer = { + .size = 0, + .type = inBuffer->type + }; + unsigned char *compData = CompressData( inBuffer->data, inBuffer->size, (int*)&outBuffer.size ); - lua_pushboolean( L, IsGamepadButtonReleased( gamepad, button ) ); + outBuffer.data = malloc( outBuffer.size ); + memcpy( outBuffer.data, compData, outBuffer.size ); + uluaPushBuffer( L, outBuffer ); + + free( compData ); return 1; } /* -> count = RL.GetGamepadAxisCount( int gamepad ) +> decompData = RL.DecompressData( Buffer compData ) -Return gamepad axis count for a gamepad +Decompress data (DEFLATE algorithm). -- Success return int +- Success Buffer */ -int lcoreGetGamepadAxisCount( lua_State *L ) { - int gamepad = luaL_checkinteger( L, 1 ); +int lcoreDecompressData( lua_State *L ) { + Buffer *inBuffer = uluaGetBuffer( L, 1 ); + Buffer outBuffer = { + .size = 0, + .type = inBuffer->type + }; + unsigned char *data = DecompressData( inBuffer->data, inBuffer->size, (int*)&outBuffer.size ); - lua_pushinteger( L, GetGamepadAxisCount( gamepad ) ); + outBuffer.data = malloc( outBuffer.size ); + memcpy( outBuffer.data, data, outBuffer.size ); + uluaPushBuffer( L, outBuffer ); + + free( data ); return 1; } /* -> value = RL.GetGamepadAxisMovement( int gamepad, int axis ) +> encodedData, outputSize = RL.EncodeDataBase64( string data ) -Return axis movement value for a gamepad axis +Encode data to Base64 string -- Success return float +- Success return string, int */ -int lcoreGetGamepadAxisMovement( lua_State *L ) { - int gamepad = luaL_checkinteger( L, 1 ); - int axis = luaL_checkinteger( L, 2 ); +int lcoreEncodeDataBase64( lua_State *L ) { + int dataSize = 0; + const char *string = luaL_checklstring( L, 1, (size_t*)&dataSize ); - lua_pushnumber( L, GetGamepadAxisMovement( gamepad, axis ) ); + int outputSize = 0; + char *compData = EncodeDataBase64( string, dataSize, &outputSize ); - return 1; + lua_pushstring( L, compData ); + lua_pushinteger( L, outputSize ); + + free( compData ); + + return 2; } /* -> name = RL.GetGamepadName( int gamepad ) +> decodedData, outputSize = RL.DecodeDataBase64( string data ) -Return gamepad internal name id +Decode Base64 string data + +- Success return string, int +*/ +int lcoreDecodeDataBase64( lua_State *L ) { + int outputSize = 0; + unsigned char *decodedData = DecodeDataBase64( luaL_checkstring( L, 1 ), &outputSize ); -- Success return string -*/ -int lcoreGetGamepadName( lua_State *L ) { - int gamepad = luaL_checkinteger( L, 1 ); + lua_pushstring( L, decodedData ); + lua_pushinteger( L, outputSize ); - lua_pushstring( L, GetGamepadName( gamepad ) ); + free( decodedData ); - return 1; + return 2; } /* -## Core - Input-related Mouse +## Core - Input-related functions: keyboard */ /* -> pressed = RL.IsMouseButtonPressed( int button ) +> pressed = RL.IsKeyPressed( int key ) -Detect if a mouse button has been pressed once +Detect if a key has been pressed once - Success return bool */ -int lcoreIsMouseButtonPressed( lua_State *L ) { - int button = luaL_checkinteger( L, 1 ); +int lcoreIsKeyPressed( lua_State *L ) { + int key = luaL_checkinteger( L, 1 ); - lua_pushboolean( L, IsMouseButtonPressed( button ) ); + lua_pushboolean( L, IsKeyPressed( key ) ); return 1; } /* -> pressed = RL.IsMouseButtonDown( int button ) +> pressed = RL.IsKeyDown( int key ) -Detect if a mouse button is being pressed +Detect if a key is being pressed - Success return bool */ -int lcoreIsMouseButtonDown( lua_State *L ) { - int button = luaL_checkinteger( L, 1 ); +int lcoreIsKeyDown( lua_State *L ) { + int key = luaL_checkinteger( L, 1 ); - lua_pushboolean( L, IsMouseButtonDown( button ) ); + lua_pushboolean( L, IsKeyDown( key ) ); return 1; } /* -> released = RL.IsMouseButtonReleased( int button ) +> released = RL.IsKeyReleased( int key ) -Detect if a mouse button has been released once +Detect if a key has been released once - Success return bool */ -int lcoreIsMouseButtonReleased( lua_State *L ) { - int button = luaL_checkinteger( L, 1 ); +int lcoreIsKeyReleased( lua_State *L ) { + int key = luaL_checkinteger( L, 1 ); - lua_pushboolean( L, IsMouseButtonReleased( button ) ); + lua_pushboolean( L, IsKeyReleased( key ) ); return 1; } /* -> released = RL.IsMouseButtonUp( int button ) +> released = RL.IsKeyUp( int key ) -Check if a mouse button is NOT being pressed +Check if a key is NOT being pressed - Success return bool */ -int lcoreIsMouseButtonUp( lua_State *L ) { - int button = luaL_checkinteger( L, 1 ); +int lcoreIsKeyUp( lua_State *L ) { + int key = luaL_checkinteger( L, 1 ); - lua_pushboolean( L, IsMouseButtonUp( button ) ); + lua_pushboolean( L, IsKeyUp( key ) ); return 1; } /* -> position = RL.GetMousePosition() +> keycode = RL.GetKeyPressed() -Returns mouse position +Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty -- Success return Vector2 +- Success return int */ -int lcoreGetMousePosition( lua_State *L ) { - uluaPushVector2( L, GetMousePosition() ); +int lcoreGetKeyPressed( lua_State *L ) { + lua_pushinteger( L, GetKeyPressed() ); return 1; } /* -> position = RL.GetMouseDelta() +> unicode = RL.GetCharPressed() -Get mouse delta between frames +Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty -- Success return Vector2 +- Success return int */ -int lcoreGetMouseDelta( lua_State *L ) { - uluaPushVector2( L, GetMouseDelta() ); +int lcoreGetCharPressed( lua_State *L ) { + lua_pushinteger( L, GetCharPressed() ); return 1; } /* -> RL.SetMousePosition( Vector2 position ) - -Set mouse position XY -*/ -int lcoreSetMousePosition( lua_State *L ) { - Vector2 pos = uluaGetVector2( L, 1 ); - - SetMousePosition( pos.x, pos.y ); - - return 0; -} - -/* -> RL.SetMouseOffset( Vector2 offset ) - -Set mouse offset -*/ -int lcoreSetMouseOffset( lua_State *L ) { - Vector2 offset = uluaGetVector2( L, 1 ); - - SetMouseOffset( offset.x, offset.y ); - - return 0; -} - -/* -> RL.SetMouseScale( Vector2 scale ) +> RL.SetExitKey( int key ) -Set mouse scaling +Set a custom key to exit program (default is ESC) */ -int lcoreSetMouseScale( lua_State *L ) { - Vector2 scale = uluaGetVector2( L, 1 ); +int lcoreSetExitKey( lua_State *L ) { + int key = luaL_checkinteger( L, 1 ); - SetMouseScale( scale.x, scale.y ); + SetExitKey( key ); return 0; } /* -> movement = RL.GetMouseWheelMove() - -Returns mouse wheel movement Y - -- Success return float -*/ -int lcoreGetMouseWheelMove( lua_State *L ) { - lua_pushnumber( L, GetMouseWheelMove() ); - - return 1; -} - -/* -> RL.SetMouseCursor( int cursor ) +> keyName = RL.GetKeyName( int key, int scancode ) -Set mouse cursor -*/ -int lcoreSetMouseCursor( lua_State *L ) { - int cursor = luaL_checkinteger( L, 1 ); +This function returns the name of the specified printable key, encoded as UTF-8. +This is typically the character that key would produce without any modifier keys, +intended for displaying key bindings to the user. For dead keys, it is typically +the diacritic it would add to a character. - SetMouseCursor( cursor ); +Do not use this function for text input. You will break text input for many +languages even if it happens to work for yours. - return 0; -} +If the key is KEY_UNKNOWN, the scancode is used to identify the key, +otherwise the scancode is ignored. If you specify a non-printable key, +or KEY_UNKNOWN and a scancode that maps to a non-printable key, +this function returns nil but does not emit an error. -/* -## Core - Input-related Touch +- Success return string or nil */ +int lcoreGetKeyName( lua_State *L ) { + int key = luaL_checkinteger( L, 1 ); + int scancode = luaL_checkinteger( L, 2 ); -/* -> position = RL.GetTouchPosition( int index ) - -Get touch position XY for a touch point index (relative to screen size) - -- Success return Vector2 -*/ -int lcoreGetTouchPosition( lua_State *L ) { - int index = luaL_checkinteger( L, 1 ); + const char *keyName = glfwGetKeyName( key, scancode ); - uluaPushVector2( L, GetTouchPosition( index ) ); + if ( keyName != NULL ) { + lua_pushstring( L, keyName ); + } + else { + lua_pushnil( L ); + } return 1; } /* -> id = RL.GetTouchPointId( int index ) +> scancode = RL.GetKeyScancode( int key ) -Get touch point identifier for given index +This function returns the platform-specific scancode of the specified key. +If the key is KEY_UNKNOWN or does not exist on the keyboard this method will return -1. - Success return int */ -int lcoreGetTouchPointId( lua_State *L ) { - int index = luaL_checkinteger( L, 1 ); +int lcoreGetKeyScancode( lua_State *L ) { + int key = luaL_checkinteger( L, 1 ); - lua_pushinteger( L, GetTouchPointId( index ) ); + lua_pushinteger( L, glfwGetKeyScancode( key ) ); return 1; } /* -> count = RL.GetTouchPointCount() - -Get touch point identifier for given index - -- Success return int +## Core - Input-related functions: gamepads */ -int lcoreGetTouchPointCount( lua_State *L ) { - lua_pushinteger( L, GetTouchPointCount() ); - - return 1; -} /* -## Core - Input-related Gestures -*/ +> available = RL.IsGamepadAvailable( int gamepad ) -/* -> RL.SetGesturesEnabled( unsigned int flags ) +Detect if a gamepad is available -Enable a set of gestures using flags +- Success return bool */ -int lcoreSetGesturesEnabled( lua_State *L ) { - unsigned int flags = (unsigned int)luaL_checkinteger( L, 1 ); +int lcoreIsGamepadAvailable( lua_State *L ) { + int gamepad = luaL_checkinteger( L, 1 ); - SetGesturesEnabled( flags ); + lua_pushboolean( L, IsGamepadAvailable( gamepad ) ); - return 0; + return 1; } /* -> detected = RL.IsGestureDetected( int gesture ) +> pressed = RL.IsGamepadButtonPressed( int gamepad, int button ) -Check if a gesture have been detected +Detect if a gamepad button has been pressed once - Success return bool */ -int lcoreIsGestureDetected( lua_State *L ) { - int gesture = luaL_checkinteger( L, 1 ); +int lcoreIsGamepadButtonPressed( lua_State *L ) { + int gamepad = luaL_checkinteger( L, 1 ); + int button = luaL_checkinteger( L, 2 ); - lua_pushboolean( L, IsGestureDetected( gesture ) ); + lua_pushboolean( L, IsGamepadButtonPressed( gamepad, button ) ); return 1; } /* -> gesture = RL.GetGestureDetected() +> pressed = RL.IsGamepadButtonDown( int gamepad, int button ) -Get latest detected gesture +Detect if a gamepad button is being pressed -- Success return int +- Success return bool */ -int lcoreGetGestureDetected( lua_State *L ) { - lua_pushinteger( L, GetGestureDetected() ); - - return 1; -} - -/* -> time = RL.GetGestureHoldDuration() - -Get gesture hold time in milliseconds +int lcoreIsGamepadButtonDown( lua_State *L ) { + int gamepad = luaL_checkinteger( L, 1 ); + int button = luaL_checkinteger( L, 2 ); -- Success return float -*/ -int lcoreGetGestureHoldDuration( lua_State *L ) { - lua_pushnumber( L, GetGestureHoldDuration() ); + lua_pushboolean( L, IsGamepadButtonDown( gamepad, button ) ); return 1; } /* -> vector = RL.GetGestureDragVector() +> released = RL.IsGamepadButtonReleased( int gamepad, int button ) -Get gesture drag vector +Detect if a gamepad button has been released once -- Success return Vector2 +- Success return bool */ -int lcoreGetGestureDragVector( lua_State *L ) { - uluaPushVector2( L, GetGestureDragVector() ); - - return 1; -} - -/* -> angle = RL.GetGestureDragAngle() - -Get gesture drag angle +int lcoreIsGamepadButtonReleased( lua_State *L ) { + int gamepad = luaL_checkinteger( L, 1 ); + int button = luaL_checkinteger( L, 2 ); -- Success return float -*/ -int lcoreGetGestureDragAngle( lua_State *L ) { - lua_pushnumber( L, GetGestureDragAngle() ); + lua_pushboolean( L, IsGamepadButtonReleased( gamepad, button ) ); return 1; } /* -> vector = RL.GetGesturePinchVector() +> count = RL.GetGamepadAxisCount( int gamepad ) -Get gesture pinch delta +Return gamepad axis count for a gamepad -- Success return Vector2 +- Success return int */ -int lcoreGetGesturePinchVector( lua_State *L ) { - uluaPushVector2( L, GetGesturePinchVector() ); +int lcoreGetGamepadAxisCount( lua_State *L ) { + int gamepad = luaL_checkinteger( L, 1 ); + + lua_pushinteger( L, GetGamepadAxisCount( gamepad ) ); return 1; } /* -> angle = RL.GetGesturePinchAngle() +> value = RL.GetGamepadAxisMovement( int gamepad, int axis ) -Get gesture pinch angle +Return axis movement value for a gamepad axis - Success return float */ -int lcoreGetGesturePinchAngle( lua_State *L ) { - lua_pushnumber( L, GetGesturePinchAngle() ); +int lcoreGetGamepadAxisMovement( lua_State *L ) { + int gamepad = luaL_checkinteger( L, 1 ); + int axis = luaL_checkinteger( L, 2 ); + + lua_pushnumber( L, GetGamepadAxisMovement( gamepad, axis ) ); return 1; } /* -## Core - File -*/ - -/* -> path = RL.GetBasePath() +> name = RL.GetGamepadName( int gamepad ) -Return game directory (where main.lua is located) +Return gamepad internal name id - Success return string */ -int lcoreGetBasePath( lua_State *L ) { - lua_pushstring( L, state->exePath ); +int lcoreGetGamepadName( lua_State *L ) { + int gamepad = luaL_checkinteger( L, 1 ); + + lua_pushstring( L, GetGamepadName( gamepad ) ); return 1; } /* -> fileExists = RL.FileExists( string fileName ) +## Core - Input-related functions: mouse +*/ -Check if file exists +/* +> pressed = RL.IsMouseButtonPressed( int button ) + +Detect if a mouse button has been pressed once - Success return bool */ -int lcoreFileExists( lua_State *L ) { - lua_pushboolean( L, FileExists( luaL_checkstring( L, 1 ) ) ); +int lcoreIsMouseButtonPressed( lua_State *L ) { + int button = luaL_checkinteger( L, 1 ); + + lua_pushboolean( L, IsMouseButtonPressed( button ) ); return 1; } /* -> dirExists = RL.DirectoryExists( string dirPath ) +> pressed = RL.IsMouseButtonDown( int button ) -Check if a directory path exists +Detect if a mouse button is being pressed - Success return bool */ -int lcoreDirectoryExists( lua_State *L ) { - lua_pushboolean( L, DirectoryExists( luaL_checkstring( L, 1 ) ) ); +int lcoreIsMouseButtonDown( lua_State *L ) { + int button = luaL_checkinteger( L, 1 ); + + lua_pushboolean( L, IsMouseButtonDown( button ) ); return 1; } /* -> hasFileExtension = RL.IsFileExtension( string fileName, string ext ) +> released = RL.IsMouseButtonReleased( int button ) -Check file extension (Including point: .png, .wav) +Detect if a mouse button has been released once - Success return bool */ -int lcoreIsFileExtension( lua_State *L ) { - lua_pushboolean( L, IsFileExtension( luaL_checkstring( L, 1 ), luaL_checkstring( L, 2 ) ) ); +int lcoreIsMouseButtonReleased( lua_State *L ) { + int button = luaL_checkinteger( L, 1 ); + + lua_pushboolean( L, IsMouseButtonReleased( button ) ); return 1; } /* -> length = RL.GetFileLength( string fileName ) +> released = RL.IsMouseButtonUp( int button ) -Get file length in bytes (NOTE: GetFileSize() conflicts with windows.h) +Check if a mouse button is NOT being pressed -- Success return int +- Success return bool */ -int lcoreGetFileLength( lua_State *L ) { - lua_pushinteger( L, GetFileLength( luaL_checkstring( L, 1 ) ) ); +int lcoreIsMouseButtonUp( lua_State *L ) { + int button = luaL_checkinteger( L, 1 ); + + lua_pushboolean( L, IsMouseButtonUp( button ) ); return 1; } /* -> extension = RL.GetFileExtension( string fileName ) +> position = RL.GetMousePosition() -Get pointer to extension for a filename string (Includes dot: '.png') +Returns mouse position -- Success return string +- Success return Vector2 */ -int lcoreGetFileExtension( lua_State *L ) { - lua_pushstring( L, GetFileExtension( luaL_checkstring( L, 1 ) ) ); +int lcoreGetMousePosition( lua_State *L ) { + uluaPushVector2( L, GetMousePosition() ); return 1; } /* -> fileName = RL.GetFileName( string filePath ) +> position = RL.GetMouseDelta() -Get pointer to filename for a path string +Get mouse delta between frames -- Success return string +- Success return Vector2 */ -int lcoreGetFileName( lua_State *L ) { - lua_pushstring( L, GetFileName( luaL_checkstring( L, 1 ) ) ); +int lcoreGetMouseDelta( lua_State *L ) { + uluaPushVector2( L, GetMouseDelta() ); return 1; } /* -> fileName = RL.GetFileNameWithoutExt( string filePath ) - -Get filename string without extension (Uses static string) +> RL.SetMousePosition( Vector2 position ) -- Success return string +Set mouse position XY */ -int lcoreGetFileNameWithoutExt( lua_State *L ) { - lua_pushstring( L, GetFileNameWithoutExt( luaL_checkstring( L, 1 ) ) ); +int lcoreSetMousePosition( lua_State *L ) { + Vector2 pos = uluaGetVector2( L, 1 ); - return 1; + SetMousePosition( pos.x, pos.y ); + + return 0; } /* -> filePath = RL.GetDirectoryPath( string filePath ) - -Get full path for a given fileName with path (Uses static string) +> RL.SetMouseOffset( Vector2 offset ) -- Success return string +Set mouse offset */ -int lcoreGetDirectoryPath( lua_State *L ) { - lua_pushstring( L, GetDirectoryPath( luaL_checkstring( L, 1 ) ) ); +int lcoreSetMouseOffset( lua_State *L ) { + Vector2 offset = uluaGetVector2( L, 1 ); - return 1; + SetMouseOffset( offset.x, offset.y ); + + return 0; } /* -> directory = RL.GetPrevDirectoryPath( string dirPath ) - -Get previous directory path for a given path (Uses static string) +> RL.SetMouseScale( Vector2 scale ) -- Success return string +Set mouse scaling */ -int lcoreGetPrevDirectoryPath( lua_State *L ) { - lua_pushstring( L, GetPrevDirectoryPath( luaL_checkstring( L, 1 ) ) ); +int lcoreSetMouseScale( lua_State *L ) { + Vector2 scale = uluaGetVector2( L, 1 ); - return 1; + SetMouseScale( scale.x, scale.y ); + + return 0; } /* -> directory = RL.GetWorkingDirectory() +> movement = RL.GetMouseWheelMove() -Get current working directory (Uses static string) +Returns mouse wheel movement Y -- Success return string +- Success return float */ -int lcoreGetWorkingDirectory( lua_State *L ) { - lua_pushstring( L, GetWorkingDirectory() ); +int lcoreGetMouseWheelMove( lua_State *L ) { + lua_pushnumber( L, GetMouseWheelMove() ); return 1; } /* -> fileNames = RL.LoadDirectoryFiles( string dirPath ) - -Load directory filepaths +> RL.SetMouseCursor( int cursor ) -- Success return string{} +Set mouse cursor */ -int lcoreLoadDirectoryFiles( lua_State *L ) { - FilePathList files = LoadDirectoryFiles( luaL_checkstring( L, 1 ) ); - - lua_createtable( L, files.count, 0 ); +int lcoreSetMouseCursor( lua_State *L ) { + int cursor = luaL_checkinteger( L, 1 ); - for ( int i = 0; i < files.count; ++i ) { - lua_pushstring( L, files.paths[i] ); - lua_rawseti( L, -2, i+1 ); - } - UnloadDirectoryFiles( files ); + SetMouseCursor( cursor ); - return 1; + return 0; } /* -> fileNames = RL.LoadDirectoryFilesEx( string basePath, string filter, bool scanSubdirs ) - -Load directory filepaths with extension filtering and recursive directory scan - -- Success return string{} +## Core - Input-related functions: touch */ -int lcoreLoadDirectoryFilesEx( lua_State *L ) { - bool scanSubdirs = uluaGetBoolean( L, 3 ); - FilePathList files = LoadDirectoryFilesEx( luaL_checkstring( L, 1 ), luaL_checkstring( L, 2 ), scanSubdirs ); +/* +> position = RL.GetTouchPosition( int index ) - lua_createtable( L, files.count, 0 ); +Get touch position XY for a touch point index (relative to screen size) - for ( int i = 0; i < files.count; ++i ) { - lua_pushstring( L, files.paths[i] ); - lua_rawseti( L, -2, i+1 ); - } - UnloadDirectoryFiles( files ); +- Success return Vector2 +*/ +int lcoreGetTouchPosition( lua_State *L ) { + int index = luaL_checkinteger( L, 1 ); + + uluaPushVector2( L, GetTouchPosition( index ) ); return 1; } /* -> success = RL.ChangeDirectory( string directory ) +> id = RL.GetTouchPointId( int index ) -Change working directory, return true on success +Get touch point identifier for given index -- Success return bool +- Success return int */ -int lcoreChangeDirectory( lua_State *L ) { - lua_pushboolean( L, ChangeDirectory( luaL_checkstring( L, 1 ) ) ); +int lcoreGetTouchPointId( lua_State *L ) { + int index = luaL_checkinteger( L, 1 ); + + lua_pushinteger( L, GetTouchPointId( index ) ); return 1; } /* -> isFile = RL.IsPathFile( string path ) +> count = RL.GetTouchPointCount() -Check if a given path is a file or a directory +Get touch point identifier for given index -- Success return bool +- Success return int */ -int lcoreIsPathFile( lua_State *L ) { - lua_pushboolean( L, IsPathFile( luaL_checkstring( L, 1 ) ) ); +int lcoreGetTouchPointCount( lua_State *L ) { + lua_pushinteger( L, GetTouchPointCount() ); return 1; } /* -> iSFileDropped = RL.IsFileDropped() +## Core - Input-related functions: gestures +*/ -Check if a file has been dropped into window +/* +> RL.SetGesturesEnabled( unsigned int flags ) -- Success return bool +Enable a set of gestures using flags */ -int lcoreIsFileDropped( lua_State *L ) { - lua_pushboolean( L, IsFileDropped() ); +int lcoreSetGesturesEnabled( lua_State *L ) { + unsigned int flags = (unsigned int)luaL_checkinteger( L, 1 ); - return 1; + SetGesturesEnabled( flags ); + + return 0; } /* -> files = RL.LoadDroppedFiles() +> detected = RL.IsGestureDetected( int gesture ) -Load dropped filepaths +Check if a gesture have been detected -- Success return string{} +- Success return bool */ -int lcoreLoadDroppedFiles( lua_State *L ) { - FilePathList files = LoadDroppedFiles(); - - lua_createtable( L, files.count, 0 ); +int lcoreIsGestureDetected( lua_State *L ) { + int gesture = luaL_checkinteger( L, 1 ); - for ( int i = 0; i < files.count; ++i ) { - lua_pushstring( L, files.paths[i] ); - lua_rawseti( L, -2, i+1 ); - } - UnloadDroppedFiles( files ); + lua_pushboolean( L, IsGestureDetected( gesture ) ); return 1; } /* -> time = RL.GetFileModTime( string fileName ) +> gesture = RL.GetGestureDetected() -Get file modification time (Last write time) +Get latest detected gesture - Success return int */ -int lcoreGetFileModTime( lua_State *L ) { - lua_pushinteger( L, GetFileModTime( luaL_checkstring( L, 1 ) ) ); +int lcoreGetGestureDetected( lua_State *L ) { + lua_pushinteger( L, GetGestureDetected() ); return 1; } /* -## Core - Compression/Encoding functionality -*/ - -/* -> compData = RL.CompressData( Buffer buffer ) +> time = RL.GetGestureHoldDuration() -Compress data (DEFLATE algorithm) +Get gesture hold time in milliseconds -- Success return Buffer +- Success return float */ -int lcoreCompressData( lua_State *L ) { - Buffer *inBuffer = uluaGetBuffer( L, 1 ); - Buffer outBuffer = { - .size = 0, - .type = inBuffer->type - }; - unsigned char *compData = CompressData( inBuffer->data, inBuffer->size, (int*)&outBuffer.size ); - - outBuffer.data = malloc( outBuffer.size ); - memcpy( outBuffer.data, compData, outBuffer.size ); - uluaPushBuffer( L, outBuffer ); - - free( compData ); +int lcoreGetGestureHoldDuration( lua_State *L ) { + lua_pushnumber( L, GetGestureHoldDuration() ); return 1; } /* -> decompData = RL.DecompressData( Buffer compData ) +> vector = RL.GetGestureDragVector() -Decompress data (DEFLATE algorithm). +Get gesture drag vector -- Success Buffer +- Success return Vector2 */ -int lcoreDecompressData( lua_State *L ) { - Buffer *inBuffer = uluaGetBuffer( L, 1 ); - Buffer outBuffer = { - .size = 0, - .type = inBuffer->type - }; - unsigned char *data = DecompressData( inBuffer->data, inBuffer->size, (int*)&outBuffer.size ); - - outBuffer.data = malloc( outBuffer.size ); - memcpy( outBuffer.data, data, outBuffer.size ); - uluaPushBuffer( L, outBuffer ); - - free( data ); +int lcoreGetGestureDragVector( lua_State *L ) { + uluaPushVector2( L, GetGestureDragVector() ); return 1; } /* -> encodedData, outputSize = RL.EncodeDataBase64( string data ) +> angle = RL.GetGestureDragAngle() -Encode data to Base64 string +Get gesture drag angle -- Success return string, int +- Success return float */ -int lcoreEncodeDataBase64( lua_State *L ) { - int dataSize = 0; - const char *string = luaL_checklstring( L, 1, (size_t*)&dataSize ); +int lcoreGetGestureDragAngle( lua_State *L ) { + lua_pushnumber( L, GetGestureDragAngle() ); - int outputSize = 0; - char *compData = EncodeDataBase64( string, dataSize, &outputSize ); + return 1; +} - lua_pushstring( L, compData ); - lua_pushinteger( L, outputSize ); +/* +> vector = RL.GetGesturePinchVector() - free( compData ); +Get gesture pinch delta - return 2; +- Success return Vector2 +*/ +int lcoreGetGesturePinchVector( lua_State *L ) { + uluaPushVector2( L, GetGesturePinchVector() ); + + return 1; } /* -> decodedData, outputSize = RL.DecodeDataBase64( string data ) +> angle = RL.GetGesturePinchAngle() -Decode Base64 string data +Get gesture pinch angle -- Success return string, int +- Success return float */ -int lcoreDecodeDataBase64( lua_State *L ) { - int outputSize = 0; - unsigned char *decodedData = DecodeDataBase64( luaL_checkstring( L, 1 ), &outputSize ); - - lua_pushstring( L, decodedData ); - lua_pushinteger( L, outputSize ); - - free( decodedData ); +int lcoreGetGesturePinchAngle( lua_State *L ) { + lua_pushnumber( L, GetGesturePinchAngle() ); - return 2; + return 1; } /* -## Core - Camera2D +## Core - Camera2D System functions */ /* @@ -2025,30 +2212,6 @@ int lcoreCreateCamera2D( lua_State *L ) { return 1; } -/* -> RL.BeginMode2D( camera2D camera ) - -Begin 2D mode with custom camera (2D) -*/ -int lcoreBeginMode2D( lua_State *L ) { - Camera2D *camera = uluaGetCamera2D( L, 1 ); - - BeginMode2D( *camera ); - - return 0; -} - -/* -> RL.EndMode2D() - -Ends 2D mode with custom camera -*/ -int lcoreEndMode2D( lua_State *L ) { - EndMode2D(); - - return 0; -} - /* > RL.SetCamera2DTarget( camera2D camera, Vector2 target ) @@ -2163,7 +2326,7 @@ int lcoreGetCamera2DZoom( lua_State *L ) { } /* -## Core - Camera3D +## Core - Camera3D System functions */ /* @@ -2187,30 +2350,6 @@ int lcoreCreateCamera3D( lua_State *L ) { return 1; } -/* -> RL.BeginMode3D( camera3D camera ) - -Begin 3D mode with custom camera (3D) -*/ -int lcoreBeginMode3D( lua_State *L ) { - Camera3D *camera = uluaGetCamera3D( L, 1 ); - - BeginMode3D( *camera ); - - return 0; -} - -/* -> RL.EndMode3D() - -Ends 3D mode and returns to default 2D orthographic mode -*/ -int lcoreEndMode3D( lua_State *L ) { - EndMode3D(); - - return 0; -} - /* > RL.SetCamera3DPosition( camera3D camera, Vector3 position ) @@ -2577,122 +2716,7 @@ int lcoreUpdateCamera3DPro( lua_State *L ) { } /* -## Core - Screen-space -*/ - -/* -> ray = RL.GetMouseRay( Vector2 mousePosition, Camera3D camera ) - -Get a ray trace from mouse position - -- Success return Ray -*/ -int lcoreGetMouseRay( lua_State *L ) { - Vector2 mousePosition = uluaGetVector2( L, 1 ); - Camera3D *camera = uluaGetCamera3D( L, 2 ); - - uluaPushRay( L, GetMouseRay( mousePosition, *camera ) ); - - return 1; -} - -/* -> matrix = RL.GetCameraMatrix( Camera3D camera ) - -Get camera transform matrix (view matrix) - -- Success return Matrix -*/ -int lcoreGetCameraMatrix( lua_State *L ) { - Camera3D *camera = uluaGetCamera3D( L, 1 ); - - uluaPushMatrix( L, GetCameraMatrix( *camera ) ); - - return 1; -} - -/* -> matrix = RL.GetCameraMatrix2D( Camera2D camera ) - -Get camera 2d transform matrix - -- Success return Matrix -*/ -int lcoreGetCameraMatrix2D( lua_State *L ) { - Camera2D *camera = uluaGetCamera2D( L, 1 ); - - uluaPushMatrix( L, GetCameraMatrix2D( *camera ) ); - - return 1; -} - -/* -> position = RL.GetWorldToScreen( Vector3 position, Camera3D camera ) - -Get the screen space position for a 3d world space position - -- Success return Vector2 -*/ -int lcoreGetWorldToScreen( lua_State *L ) { - Vector3 position = uluaGetVector3( L, 1 ); - Camera3D *camera = uluaGetCamera3D( L, 2 ); - - uluaPushVector2( L, GetWorldToScreen( position, *camera ) ); - - return 1; -} - -/* -> position = RL.GetWorldToScreenEx( Vector3 position, Camera3D camera, Vector2 size ) - -Get size position for a 3d world space position - -- Success return Vector2 -*/ -int lcoreGetWorldToScreenEx( lua_State *L ) { - Vector3 position = uluaGetVector3( L, 1 ); - Camera3D *camera = uluaGetCamera3D( L, 2 ); - Vector2 size = uluaGetVector2( L, 3 ); - - uluaPushVector2( L, GetWorldToScreenEx( position, *camera, size.x, size.y ) ); - - return 1; -} - -/* -> position = RL.GetWorldToScreen2D( Vector2 position, Camera2D camera ) - -Get the screen space position for a 2d camera world space position - -- Success return Vector2 -*/ -int lcoreGetWorldToScreen2D( lua_State *L ) { - Vector2 position = uluaGetVector2( L, 1 ); - Camera2D *camera = uluaGetCamera2D( L, 2 ); - - uluaPushVector2( L, GetWorldToScreen2D( position, *camera ) ); - - return 1; -} - -/* -> position = RL.GetScreenToWorld2D( Vector2 position, Camera2D camera ) - -Get the world space position for a 2d camera screen space position - -- Success return Vector2 -*/ -int lcoreGetScreenToWorld2D( lua_State *L ) { - Vector2 position = uluaGetVector2( L, 1 ); - Camera2D *camera = uluaGetCamera2D( L, 2 ); - - uluaPushVector2( L, GetScreenToWorld2D( position, *camera ) ); - - return 1; -} - -/* -## Core - Buffer +## Core - Buffer management functions */ /* -- cgit v1.2.3