summaryrefslogtreecommitdiff
path: root/src/core.c
diff options
context:
space:
mode:
authorjussi2023-11-20 21:04:53 +0200
committerjussi2023-11-20 21:04:53 +0200
commit05eaafb79e6fa1bebff157e94563334d7ead700b (patch)
tree574ae0af685967df067efe11058dc50478558333 /src/core.c
parent7765a23a2c90e6d02f6278eed1b1b9b9375bc941 (diff)
downloadreilua-enhanced-05eaafb79e6fa1bebff157e94563334d7ead700b.tar.gz
reilua-enhanced-05eaafb79e6fa1bebff157e94563334d7ead700b.tar.bz2
reilua-enhanced-05eaafb79e6fa1bebff157e94563334d7ead700b.zip
Initial changes for Raylib 5.0 and some missing functions.
Diffstat (limited to 'src/core.c')
-rw-r--r--src/core.c454
1 files changed, 316 insertions, 138 deletions
diff --git a/src/core.c b/src/core.c
index 4271e68..2ad6bf8 100644
--- a/src/core.c
+++ b/src/core.c
@@ -29,6 +29,17 @@ void unloadBuffer( Buffer *buffer ) {
*/
/*
+> RL.CloseWindow()
+
+Close window and unload OpenGL context and free all resources
+*/
+int lcoreCloseWindow( lua_State *L ) {
+ state->run = false;
+
+ return 0;
+}
+
+/*
> state = RL.IsWindowReady()
Check if window has been initialized successfully
@@ -107,243 +118,292 @@ int lcoreIsWindowFocused( lua_State *L ) {
}
/*
-> RL.SetWindowMonitor( int monitor )
+> resized = RL.IsWindowResized()
-Set monitor for the current window (fullscreen mode)
-*/
-int lcoreSetWindowMonitor( lua_State *L ) {
- int monitor = luaL_checkinteger( L, 1 );
+Check if window has been resized from last frame
- SetWindowMonitor( monitor );
+- Success return bool
+*/
+int lcoreIsWindowResized( lua_State *L ) {
+ lua_pushboolean( L, IsWindowResized() );
- return 0;
+ return 1;
}
/*
-> RL.SetWindowPosition( Vector2 pos )
+> state = RL.IsWindowState( int flag )
-Set window position on screen
+Check if one specific window flag is enabled (FLAG_FULLSCREEN_MODE, FLAG_WINDOW_RESIZABLE...)
+
+- Success return bool
*/
-int lcoreSetWindowPosition( lua_State *L ) {
- Vector2 pos = uluaGetVector2( L, 1 );
+int lcoreIsWindowState( lua_State *L ) {
+ unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 );
- SetWindowPosition( pos.x, pos.y );
+ lua_pushboolean( L, IsWindowState( flag ) );
- return 0;
+ return 1;
}
/*
-> RL.SetWindowSize( Vector2 size )
+> RL.SetWindowState( int flag )
-Set window dimensions
+Set window configuration state using flags (FLAG_FULLSCREEN_MODE, FLAG_WINDOW_RESIZABLE...)
*/
-int lcoreSetWindowSize( lua_State *L ) {
- Vector2 size = uluaGetVector2( L, 1 );
+int lcoreSetWindowState( lua_State *L ) {
+ unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 );
- SetWindowSize( (int)size.x, (int)size.y );
+ SetWindowState( flag );
return 0;
}
/*
-> RL.SetWindowOpacity( float opacity )
+> resized = RL.ClearWindowState( int flag )
-Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
+Clear window configuration state flags (FLAG_FULLSCREEN_MODE, FLAG_WINDOW_RESIZABLE...)
+
+- Success return bool
*/
-int lcoreSetWindowOpacity( lua_State *L ) {
- float opacity = luaL_checknumber( L, 1 );
+int lcoreClearWindowState( lua_State *L ) {
+ unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 );
- SetWindowOpacity( opacity );
+ ClearWindowState( flag );
- return 0;
+ return 1;
}
/*
-> windowHandle = RL.GetWindowHandle()
+> RL.ToggleFullscreen()
-Get native window handle. Return as lightuserdata
+Toggle window state: fullscreen/windowed (only PLATFORM_DESKTOP)
+*/
+int lcoreToggleFullscreen( lua_State *L ) {
+ ToggleFullscreen();
-- Success return lightuserdata
+ return 0;
+}
+
+/*
+> RL.ToggleBorderlessWindowed()
+
+Toggle window state: borderless windowed (only PLATFORM_DESKTOP)
*/
-int lcoreGetWindowHandle( lua_State *L ) {
- lua_pushlightuserdata( L, GetWindowHandle() );
+int lcoreToggleBorderlessWindowed( lua_State *L ) {
+ ToggleBorderlessWindowed();
- return 1;
+ return 0;
}
/*
-> RL.SetWindowMinSize( Vector2 size )
+> RL.MaximizeWindow()
-Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
+Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
*/
-int lcoreSetWindowMinSize( lua_State *L ) {
- Vector2 size = uluaGetVector2( L, 1 );
+int lcoreMaximizeWindow( lua_State *L ) {
+ MaximizeWindow();
- SetWindowMinSize( (int)size.x, (int)size.y );
+ return 0;
+}
+
+/*
+> RL.MinimizeWindow()
+
+Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
+*/
+int lcoreMinimizeWindow( lua_State *L ) {
+ MinimizeWindow();
return 0;
}
/*
-> position = RL.GetMonitorPosition( int monitor )
+> RL.RestoreWindow()
-Get specified monitor position
+Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
+*/
+int lcoreRestoreWindow( lua_State *L ) {
+ RestoreWindow();
-- Success return Vector2
+ return 0;
+}
+
+/*
+> RL.SetWindowIcon( Image image )
+
+Set icon for window (Only PLATFORM_DESKTOP)
*/
-int lcoreGetMonitorPosition( lua_State *L ) {
- int monitor = luaL_checkinteger( L, 1 );
+int lcoreSetWindowIcon( lua_State *L ) {
+ Image *image = uluaGetImage( L, 1 );
- uluaPushVector2( L, GetMonitorPosition( monitor ) );
+ SetWindowIcon( *image );
- return 1;
+ return 0;
}
/*
-> size = RL.GetMonitorSize( int monitor )
-
-Get specified monitor size
+> RL.SetWindowIcons( Image{} images )
-- Success return Vector2
+Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
*/
-int lcoreGetMonitorSize( lua_State *L ) {
- int monitor = luaL_checkinteger( L, 1 );
+int lcoreSetWindowIcons( lua_State *L ) {
+ int count = uluaGetTableLen( L, 1 );
+ Image images[ count ];
- Vector2 size = (Vector2){ GetMonitorWidth( monitor ), GetMonitorHeight( monitor ) };
- uluaPushVector2( L, size );
+ int t = 1;
+ int i = 0;
+ lua_pushnil( L );
- return 1;
+ while ( lua_next( L, t ) != 0 ) {
+ images[i] = *uluaGetImage( L, lua_gettop( L ) );
+
+ i++;
+ lua_pop( L, 1 );
+ }
+ SetWindowIcons( images, count );
+
+ return 0;
}
/*
-> position = RL.GetWindowPosition()
-
-Get window position on monitor
+> RL.SetWindowTitle( string title )
-- Success return Vector2
+Set title for window (only PLATFORM_DESKTOP and PLATFORM_WEB)
*/
-int lcoreGetWindowPosition( lua_State *L ) {
- uluaPushVector2( L, GetWindowPosition() );
+int lcoreSetWindowTitle( lua_State *L ) {
+ SetWindowTitle( luaL_checkstring( L, 1 ) );
- return 1;
+ return 0;
}
/*
-> size = RL.GetScreenSize()
-
-Get screen size
+> RL.SetWindowPosition( Vector2 pos )
-- Success return Vector2
+Set window position on screen
*/
-int lcoreGetScreenSize( lua_State *L ) {
- Vector2 size = (Vector2){ GetScreenWidth(), GetScreenHeight() };
- uluaPushVector2( L, size );
+int lcoreSetWindowPosition( lua_State *L ) {
+ Vector2 pos = uluaGetVector2( L, 1 );
- return 1;
+ SetWindowPosition( pos.x, pos.y );
+
+ return 0;
}
/*
-> RL.SetWindowState( int flag )
+> RL.SetWindowMonitor( int monitor )
-Set window configuration state using flags (FLAG_FULLSCREEN_MODE, FLAG_WINDOW_RESIZABLE...)
+Set monitor for the current window
*/
-int lcoreSetWindowState( lua_State *L ) {
- unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 );
+int lcoreSetWindowMonitor( lua_State *L ) {
+ int monitor = luaL_checkinteger( L, 1 );
- SetWindowState( flag );
+ SetWindowMonitor( monitor );
return 0;
}
/*
-> state = RL.IsWindowState( int flag )
-
-Check if one specific window flag is enabled (FLAG_FULLSCREEN_MODE, FLAG_WINDOW_RESIZABLE...)
+> RL.SetWindowMinSize( Vector2 size )
-- Success return bool
+Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
*/
-int lcoreIsWindowState( lua_State *L ) {
- unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 );
+int lcoreSetWindowMinSize( lua_State *L ) {
+ Vector2 size = uluaGetVector2( L, 1 );
- lua_pushboolean( L, IsWindowState( flag ) );
+ SetWindowMinSize( (int)size.x, (int)size.y );
- return 1;
+ return 0;
}
/*
-> resized = RL.ClearWindowState( int flag )
-
-Clear window configuration state flags (FLAG_FULLSCREEN_MODE, FLAG_WINDOW_RESIZABLE...)
+> RL.SetWindowMaxSize( Vector2 size )
-- Success return bool
+Set window maximum dimensions (for FLAG_WINDOW_RESIZABLE)
*/
-int lcoreClearWindowState( lua_State *L ) {
- unsigned int flag = (unsigned int)luaL_checkinteger( L, 1 );
+int lcoreSetWindowMaxSize( lua_State *L ) {
+ Vector2 size = uluaGetVector2( L, 1 );
- ClearWindowState( flag );
+ SetWindowMaxSize( (int)size.x, (int)size.y );
- return 1;
+ return 0;
}
/*
-> resized = RL.IsWindowResized()
-
-Check if window has been resized from last frame
+> RL.SetWindowSize( Vector2 size )
-- Success return bool
+Set window dimensions
*/
-int lcoreIsWindowResized( lua_State *L ) {
- lua_pushboolean( L, IsWindowResized() );
+int lcoreSetWindowSize( lua_State *L ) {
+ Vector2 size = uluaGetVector2( L, 1 );
- return 1;
+ SetWindowSize( (int)size.x, (int)size.y );
+
+ return 0;
}
/*
-> RL.SetWindowIcon( Image image )
+> RL.SetWindowOpacity( float opacity )
-Set icon for window (Only PLATFORM_DESKTOP)
+Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
*/
-int lcoreSetWindowIcon( lua_State *L ) {
- Image *image = uluaGetImage( L, 1 );
+int lcoreSetWindowOpacity( lua_State *L ) {
+ float opacity = luaL_checknumber( L, 1 );
- SetWindowIcon( *image );
+ SetWindowOpacity( opacity );
return 0;
}
/*
-> RL.SetWindowIcons( Image{} images )
+> RL.SetWindowFocused()
-Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
+Set window focused (only PLATFORM_DESKTOP)
*/
-int lcoreSetWindowIcons( lua_State *L ) {
- int count = uluaGetTableLen( L, 1 );
- Image images[ count ];
+int lcoreSetWindowFocused( lua_State *L ) {
+ SetWindowFocused();
- int t = 1;
- int i = 0;
- lua_pushnil( L );
+ return 0;
+}
- while ( lua_next( L, t ) != 0 ) {
- images[i] = *uluaGetImage( L, lua_gettop( L ) );
+/*
+> windowHandle = RL.GetWindowHandle()
- i++;
- lua_pop( L, 1 );
- }
- SetWindowIcons( images, count );
+Get native window handle. Return as lightuserdata
- return 0;
+- Success return lightuserdata
+*/
+int lcoreGetWindowHandle( lua_State *L ) {
+ lua_pushlightuserdata( L, GetWindowHandle() );
+
+ return 1;
}
/*
-> RL.SetWindowTitle( string title )
+> size = RL.GetScreenSize()
+
+Get screen size
-Set title for window (Only PLATFORM_DESKTOP)
+- Success return Vector2
*/
-int lcoreSetWindowTitle( lua_State *L ) {
- SetWindowTitle( luaL_checkstring( L, 1 ) );
+int lcoreGetScreenSize( lua_State *L ) {
+ Vector2 size = (Vector2){ GetScreenWidth(), GetScreenHeight() };
+ uluaPushVector2( L, size );
- return 0;
+ return 1;
+}
+
+/*
+> size = RL.GetRenderSize()
+
+Get render size
+
+- Success return Vector2
+*/
+int lcoreGetRenderSize( lua_State *L ) {
+ Vector2 size = (Vector2){ GetRenderWidth(), GetRenderHeight() };
+ uluaPushVector2( L, size );
+
+ return 1;
}
/*
@@ -373,6 +433,37 @@ int lcoreGetCurrentMonitor( lua_State *L ) {
}
/*
+> position = RL.GetMonitorPosition( int monitor )
+
+Get specified monitor position
+
+- Success return Vector2
+*/
+int lcoreGetMonitorPosition( lua_State *L ) {
+ int monitor = luaL_checkinteger( L, 1 );
+
+ uluaPushVector2( L, GetMonitorPosition( monitor ) );
+
+ return 1;
+}
+
+/*
+> size = RL.GetMonitorSize( int monitor )
+
+Get specified monitor size
+
+- Success return Vector2
+*/
+int lcoreGetMonitorSize( lua_State *L ) {
+ int monitor = luaL_checkinteger( L, 1 );
+
+ Vector2 size = (Vector2){ GetMonitorWidth( monitor ), GetMonitorHeight( monitor ) };
+ uluaPushVector2( L, size );
+
+ return 1;
+}
+
+/*
> size = RL.GetMonitorPhysicalSize( int monitor )
Get specified monitor physical size in millimetres
@@ -404,6 +495,19 @@ int lcoreGetMonitorRefreshRate( lua_State *L ) {
}
/*
+> position = RL.GetWindowPosition()
+
+Get window position on monitor
+
+- Success return Vector2
+*/
+int lcoreGetWindowPosition( lua_State *L ) {
+ uluaPushVector2( L, GetWindowPosition() );
+
+ return 1;
+}
+
+/*
> dpi = RL.GetWindowScaleDPI()
Get window scale DPI factor
@@ -419,7 +523,7 @@ int lcoreGetWindowScaleDPI( lua_State *L ) {
/*
> name = RL.GetMonitorName( int monitor )
-Get the human-readable, UTF-8 encoded name of the monitor
+Get the human-readable, UTF-8 encoded name of the specified monitor
- Success return string
*/
@@ -432,17 +536,6 @@ int lcoreGetMonitorName( lua_State *L ) {
}
/*
-> RL.CloseWindow()
-
-Close window and unload OpenGL context and free all resources
-*/
-int lcoreCloseWindow( lua_State *L ) {
- state->run = false;
-
- return 0;
-}
-
-/*
> RL.SetClipboardText( string text )
Set clipboard text content
@@ -1152,6 +1245,63 @@ int lcoreGetTime( lua_State *L ) {
}
/*
+## Core - Random values generation functions
+*/
+
+/*
+> RL.SetRandomSeed( int seed )
+
+Set the seed for the random number generator
+*/
+int lcoreSetRandomSeed( lua_State *L ) {
+ unsigned int seed = (unsigned int)luaL_checkinteger( L, 1 );
+
+ SetRandomSeed( seed );
+
+ return 0;
+}
+
+/*
+> time = RL.GetRandomValue( int min, int max )
+
+Get a random value between min and max (both included)
+
+- Success return int
+*/
+int lcoreGetRandomValue( lua_State *L ) {
+ int min = luaL_checkinteger( L, 1 );
+ int max = luaL_checkinteger( L, 2 );
+
+ lua_pushinteger( L, GetRandomValue( min, max ) );
+
+ return 1;
+}
+
+/*
+> sequence = RL.GetRandomValue( int count, int min, int max )
+
+Load random values sequence, no values repeated
+
+- Success return int{}
+*/
+int lcoreLoadRandomSequence( lua_State *L ) {
+ unsigned int count = luaL_checkinteger( L, 1 );
+ int min = luaL_checkinteger( L, 1 );
+ int max = luaL_checkinteger( L, 2 );
+
+ int *sequence = LoadRandomSequence( count, min, max );
+ lua_createtable( L, count, 0 );
+
+ for ( int i = 0; i < count; i++ ) {
+ lua_pushinteger( L, sequence[i] );
+ lua_rawseti( L, -2, i + 1 );
+ }
+ UnloadRandomSequence( sequence );
+
+ return 1;
+}
+
+/*
## Core - Misc
*/
@@ -1232,7 +1382,7 @@ int lcoreGetLogLevelInvalid( lua_State *L ) {
/*
> RL.OpenURL( string url )
-Open URL with default system browser (If available)
+Open URL with default system browser (if available)
*/
int lcoreOpenURL( lua_State *L ) {
OpenURL( luaL_checkstring( L, 1 ) );
@@ -1412,6 +1562,19 @@ int lcoreGetWorkingDirectory( lua_State *L ) {
}
/*
+> directory = RL.GetApplicationDirectory()
+
+Get the directory of the running application (uses static string)
+
+- Success return string
+*/
+int lcoreGetApplicationDirectory( lua_State *L ) {
+ lua_pushstring( L, GetApplicationDirectory() );
+
+ return 1;
+}
+
+/*
> fileNames = RL.LoadDirectoryFiles( string dirPath )
Load directory filepaths
@@ -1794,6 +1957,21 @@ int lcoreIsGamepadAvailable( lua_State *L ) {
}
/*
+> name = RL.GetGamepadName( int gamepad )
+
+Return gamepad internal name id
+
+- Success return string
+*/
+int lcoreGetGamepadName( lua_State *L ) {
+ int gamepad = luaL_checkinteger( L, 1 );
+
+ lua_pushstring( L, GetGamepadName( gamepad ) );
+
+ return 1;
+}
+
+/*
> pressed = RL.IsGamepadButtonPressed( int gamepad, int button )
Detect if a gamepad button has been pressed once
@@ -1873,16 +2051,16 @@ int lcoreGetGamepadAxisMovement( lua_State *L ) {
}
/*
-> name = RL.GetGamepadName( int gamepad )
+> result = RL.SetGamepadMappings( string mappings )
-Return gamepad internal name id
+Set internal gamepad mappings (SDL_GameControllerDB)
-- Success return string
+- Success return int
*/
-int lcoreGetGamepadName( lua_State *L ) {
- int gamepad = luaL_checkinteger( L, 1 );
+int lcoreSetGamepadMappings( lua_State *L ) {
+ const char *mappings = luaL_checkstring( L, 1 );
- lua_pushstring( L, GetGamepadName( gamepad ) );
+ lua_pushnumber( L, SetGamepadMappings( mappings ) );
return 1;
}