summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjussi2023-10-28 14:15:20 +0300
committerjussi2023-10-28 14:15:20 +0300
commitaf03c7364ea0dfe2c8bb269eb8a8f9b580f39633 (patch)
tree8ef09eefe38c890112972768c6861432028d8945
parent23935aefca3212c989199cd7e195c02b01ef14ae (diff)
downloadreilua-enhanced-af03c7364ea0dfe2c8bb269eb8a8f9b580f39633.tar.gz
reilua-enhanced-af03c7364ea0dfe2c8bb269eb8a8f9b580f39633.tar.bz2
reilua-enhanced-af03c7364ea0dfe2c8bb269eb8a8f9b580f39633.zip
New object type Font.
-rw-r--r--API.md67
-rw-r--r--ReiLua_API.lua68
-rw-r--r--changelog1
-rw-r--r--examples/window/main.lua3
-rw-r--r--include/lua_core.h1
-rw-r--r--include/state.h5
-rw-r--r--include/text.h4
-rw-r--r--src/lua_core.c34
-rw-r--r--src/rgui.c22
-rw-r--r--src/state.c15
-rw-r--r--src/text.c303
-rw-r--r--src/textures.c2
12 files changed, 171 insertions, 354 deletions
diff --git a/API.md b/API.md
index cce1b73..d8b5cb4 100644
--- a/API.md
+++ b/API.md
@@ -3853,39 +3853,35 @@ Get pixel data size in bytes for certain format
---
-> font = RL.LoadFont( string fileName )
+> RL.GetFontDefault()
-Load font from file into GPU memory ( VRAM )
-
-- Failure return -1
-- Success return int
+Get the default Font
---
-> font = RL.LoadFontEx( string fileName, int fontSize )
+> font = RL.LoadFont( string fileName )
-Load font from file with extended parameters. Loading the default character set
+Load font from file into GPU memory (VRAM)
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Font
---
-> font = RL.LoadFontFromImage( Image image, Color key, int firstChar )
+> font = RL.LoadFontEx( string fileName, int fontSize, int fontChars{} )
-Load font from Image ( XNA style )
+Load font from file with extended parameters. Loading the default character set
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Font
---
-> success = RL.UnloadFont( Font font )
+> font = RL.LoadFontFromImage( Image image, Color key, int firstChar )
-Unload Font from GPU memory ( VRAM )
+Load font from Image ( XNA style )
-- Failure return false
-- Success return true
+- Success return Font
---
@@ -3893,30 +3889,21 @@ Unload Font from GPU memory ( VRAM )
---
-> success = RL.DrawFPS( Vector2 pos )
+> RL.DrawFPS( Vector2 pos )
Draw current FPS
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
+> RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text using font and additional parameters
-- Failure return false
-- Success return true
-
---
-> success = RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
-
-Draw text using Font and pro parameters ( rotation )
+> RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
-- Failure return false
-- Success return true
+Draw text using Font and pro parameters (rotation)
---
@@ -3928,16 +3915,14 @@ Draw text using Font and pro parameters ( rotation )
Measure string size for Font
-- Failure return false
- Success return Vector2
---
> baseSize = RL.GetFontBaseSize( Font font )
-Get font base size ( default chars height )
+Get font base size (default chars height)
-- Failure return false
- Success return int
---
@@ -3946,7 +3931,6 @@ Get font base size ( default chars height )
Get font number of glyph characters
-- Failure return false
- Success return int
---
@@ -3955,17 +3939,15 @@ Get font number of glyph characters
Get font padding around the glyph characters
-- Failure return false
- Success return int
---
-> textureTable = RL.GetFontTexture( Font font )
+> texture = RL.GetFontTexture( Font font )
-Get font texture atlas containing the glyphs. NOTE! Texture in table form.
+Get font texture atlas containing the glyphs.
-- Failure return false
-- Success return table
+- Success return Texture
---
@@ -6067,12 +6049,9 @@ Get gui state ( global state )
---
-> success = RL.GuiSetFont( Font font )
-
-Set gui custom font ( global state )
+> RL.GuiSetFont( Font font )
-- Failure return false
-- Success return true
+Set gui custom font (global state)
---
diff --git a/ReiLua_API.lua b/ReiLua_API.lua
index e6edfc7..8b5a5f1 100644
--- a/ReiLua_API.lua
+++ b/ReiLua_API.lua
@@ -2794,61 +2794,52 @@ function RL.GetPixelDataSize( width, height, format ) end
-- Text - Loading
----Load font from file into GPU memory ( VRAM )
----- Failure return -1
----- Success return int
+---Get the default Font
+---@return any RL.GetFontDefault
+function RL.GetFontDefault() end
+
+---Load font from file into GPU memory (VRAM)
+---- Failure return nil
+---- Success return Font
---@param fileName string
---@return any font
function RL.LoadFont( fileName ) end
---Load font from file with extended parameters. Loading the default character set
----- Failure return -1
----- Success return int
+---- Failure return nil
+---- Success return Font
---@param fileName string
---@param fontSize integer
+---@param fontChars{} integer
---@return any font
-function RL.LoadFontEx( fileName, fontSize ) end
+function RL.LoadFontEx( fileName, fontSize, fontChars{} ) end
---Load font from Image ( XNA style )
----- Failure return -1
----- Success return int
+---- Success return Font
---@param image any
---@param key table
---@param firstChar integer
---@return any font
function RL.LoadFontFromImage( image, key, firstChar ) end
----Unload Font from GPU memory ( VRAM )
----- Failure return false
----- Success return true
----@param font any
----@return any success
-function RL.UnloadFont( font ) end
-
-- Text - Draw
---Draw current FPS
----- Failure return false
----- Success return true
---@param pos table
----@return any success
-function RL.DrawFPS( pos ) end
+---@return any RL.DrawFPS
+function RL.DrawFPS( pos ) end
---Draw text using font and additional parameters
----- Failure return false
----- Success return true
---@param font any
---@param text string
---@param position table
---@param fontSize number
---@param spacing number
---@param tint table
----@return any success
-function RL.DrawText( font, text, position, fontSize, spacing, tint ) end
+---@return any RL.DrawText
+function RL.DrawText( font, text, position, fontSize, spacing, tint ) end
----Draw text using Font and pro parameters ( rotation )
----- Failure return false
----- Success return true
+---Draw text using Font and pro parameters (rotation)
---@param font any
---@param text string
---@param position table
@@ -2857,13 +2848,12 @@ function RL.DrawText( font, text, position, fontSize, spacing, tint ) end
---@param fontSize number
---@param spacing number
---@param tint table
----@return any success
-function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spacing, tint ) end
+---@return any RL.DrawTextPro
+function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spacing, tint ) end
-- Text - Misc
---Measure string size for Font
----- Failure return false
---- Success return Vector2
---@param font any
---@param text string
@@ -2872,32 +2862,28 @@ function RL.DrawTextPro( font, text, position, origin, rotation, fontSize, spaci
---@return any size
function RL.MeasureText( font, text, fontSize, spacing ) end
----Get font base size ( default chars height )
----- Failure return false
+---Get font base size (default chars height)
---- Success return int
---@param font any
---@return any baseSize
function RL.GetFontBaseSize( font ) end
---Get font number of glyph characters
----- Failure return false
---- Success return int
---@param font any
---@return any glyphCount
function RL.GetFontGlyphCount( font ) end
---Get font padding around the glyph characters
----- Failure return false
---- Success return int
---@param font any
---@return any glyphPadding
function RL.GetFontGlyphPadding( font ) end
----Get font texture atlas containing the glyphs. NOTE! Texture in table form.
----- Failure return false
----- Success return table
+---Get font texture atlas containing the glyphs.
+---- Success return Texture
---@param font any
----@return any textureTable
+---@return any texture
function RL.GetFontTexture( font ) end
-- Models - Basic
@@ -4784,12 +4770,10 @@ function RL.GuiGetState() end
-- Gui - Font
----Set gui custom font ( global state )
----- Failure return false
----- Success return true
+---Set gui custom font (global state)
---@param font any
----@return any success
-function RL.GuiSetFont( font ) end
+---@return any RL.GuiSetFont
+function RL.GuiSetFont( font ) end
---Get gui custom font ( global state )
---- Success return int
diff --git a/changelog b/changelog
index b7b8838..109167d 100644
--- a/changelog
+++ b/changelog
@@ -14,6 +14,7 @@ DETAILED CHANGES:
- ADDED: GetRenderTextureTexture and GetRenderTextureDepthTexture.
- REMOVED: UnloadCamera2D and UnloadCamera3D.
- REMOVED: UnloadShader.
+ - ADDED: LoadFontEx takes also fontChars.
------------------------------------------------------------------------
Release: ReiLua version 0.5.0 Using Raylib 4.5
diff --git a/examples/window/main.lua b/examples/window/main.lua
index 2fcba93..2b4a009 100644
--- a/examples/window/main.lua
+++ b/examples/window/main.lua
@@ -11,7 +11,6 @@ function RL.init()
print( "path", path )
texture = RL.LoadTexture( path )
-
print( "texture", texture )
end
@@ -33,5 +32,5 @@ end
function RL.draw()
RL.ClearBackground( RL.RAYWHITE )
RL.DrawTexture( texture, { 20, 20 }, RL.WHITE )
- RL.DrawText( 0, text, textPos, 20, 2, textColor )
+ RL.DrawText( RL.fontDefault, text, textPos, 20, 2, textColor )
end
diff --git a/include/lua_core.h b/include/lua_core.h
index 1efaf1c..c90464e 100644
--- a/include/lua_core.h
+++ b/include/lua_core.h
@@ -74,6 +74,7 @@ void uluaPushRenderTexture( lua_State *L, RenderTexture renderTexture );
void uluaPushCamera2D( lua_State *L, Camera2D camera );
void uluaPushCamera3D( lua_State *L, Camera3D camera );
void uluaPushShader( lua_State *L, Shader shader );
+void uluaPushFont( lua_State *L, Font font );
int uluaGetTableLen( lua_State *L );
int uluaGetTableLenIndex( lua_State *L, int index );
diff --git a/include/state.h b/include/state.h
index a0b17fa..bf86d00 100644
--- a/include/state.h
+++ b/include/state.h
@@ -13,13 +13,8 @@ typedef struct {
bool run;
lua_State *luaState;
Vector2 resolution;
- size_t guiFont;
int logLevelInvalid;
/* Resources. */
- /* Fonts. */
- Font **fonts;
- size_t fontCount;
- size_t fontAlloc;
/* Sounds. */
Wave **waves;
size_t waveCount;
diff --git a/include/text.h b/include/text.h
index 943cbca..1c3ef40 100644
--- a/include/text.h
+++ b/include/text.h
@@ -1,12 +1,10 @@
#pragma once
-/* Validators. */
-bool validFont( size_t id );
/* Loading. */
+int ltextGetFontDefault( lua_State *L );
int ltextLoadFont( lua_State *L );
int ltextLoadFontEx( lua_State *L );
int ltextLoadFontFromImage( lua_State *L );
-int ltextUnloadFont( lua_State *L );
/* Drawing. */
int ltextDrawFPS( lua_State *L );
int ltextDrawText( lua_State *L );
diff --git a/src/lua_core.c b/src/lua_core.c
index d388c88..385ec93 100644
--- a/src/lua_core.c
+++ b/src/lua_core.c
@@ -122,6 +122,24 @@ static void defineShader() {
lua_setfield( L, -2, "__gc" );
}
+/* Font. */
+static int gcFont( lua_State *L ) {
+ Font *font = luaL_checkudata ( L, 1, "Font" );
+ printf( "gcFont\n" );
+
+ UnloadFont( *font );
+}
+
+static void defineFont() {
+ lua_State *L = state->luaState;
+
+ luaL_newmetatable( L, "Font" );
+ lua_pushvalue( L, -1 );
+ lua_setfield( L, -2, "__index" );
+ lua_pushcfunction( L, gcFont );
+ lua_setfield( L, -2, "__gc" );
+}
+
/* Assing globals. */
static void assignGlobalInt( int value, const char *name ) {
@@ -161,6 +179,9 @@ static void defineGlobals() {
lua_setglobal( L, "RL" );
lua_getglobal( L, "RL" );
+ uluaPushFont( L, GetFontDefault() );
+ lua_setfield( L, -2, "fontDefault" );
+
/*DOC_START*/
/* ConfigFlags */
assignGlobalInt( FLAG_VSYNC_HINT, "FLAG_VSYNC_HINT" );
@@ -1130,10 +1151,8 @@ bool luaInit( int argn, const char **argc ) {
if ( L == NULL ) {
TraceLog( LOG_WARNING, "%s", "Failed to init Lua" );
-
return false;
}
- defineGlobals();
/* Define object types. */
defineBuffer();
defineImage();
@@ -1142,6 +1161,9 @@ bool luaInit( int argn, const char **argc ) {
defineCamera2D();
defineCamera3D();
defineShader();
+ defineFont();
+ /* Define globals. */
+ defineGlobals();
/* Set arguments. */
lua_getglobal( L, "RL" );
@@ -1733,10 +1755,10 @@ void luaRegister() {
/* Text. */
/* Loading. */
+ assingGlobalFunction( "GetFontDefault", ltextGetFontDefault );
assingGlobalFunction( "LoadFont", ltextLoadFont );
assingGlobalFunction( "LoadFontEx", ltextLoadFontEx );
assingGlobalFunction( "LoadFontFromImage", ltextLoadFontFromImage );
- assingGlobalFunction( "UnloadFont", ltextUnloadFont );
/* Drawing. */
assingGlobalFunction( "DrawFPS", ltextDrawFPS );
assingGlobalFunction( "DrawText", ltextDrawText );
@@ -2871,6 +2893,12 @@ void uluaPushShader( lua_State *L, Shader shader ) {
luaL_setmetatable( L, "Shader" );
}
+void uluaPushFont( lua_State *L, Font font ) {
+ Font *fontP = lua_newuserdata( L, sizeof( Font ) );
+ *fontP = font;
+ luaL_setmetatable( L, "Font" );
+}
+
int uluaGetTableLen( lua_State *L ) {
return uluaGetTableLenIndex( L, lua_gettop( L ) );
}
diff --git a/src/rgui.c b/src/rgui.c
index fe2806d..2a8e290 100644
--- a/src/rgui.c
+++ b/src/rgui.c
@@ -129,26 +129,16 @@ int lguiGuiGetState( lua_State *L ) {
*/
/*
-> success = RL.GuiSetFont( Font font )
+> RL.GuiSetFont( Font font )
-Set gui custom font ( global state )
-
-- Failure return false
-- Success return true
+Set gui custom font (global state)
*/
int lguiGuiSetFont( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GuiSetFont( Font font )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
- state->guiFont = fontId;
+ Font *font = luaL_checkudata( L, 1, "Font" );
- GuiSetFont( *state->fonts[ fontId ] );
- lua_pushboolean( L, true );
+ GuiSetFont( *font );
- return 1;
+ return 0;
}
/*
@@ -159,7 +149,7 @@ Get gui custom font ( global state )
- Success return int
*/
int lguiGuiGetFont( lua_State *L ) {
- lua_pushinteger( L, state->guiFont );
+ uluaPushFont( L, GuiGetFont() );
return 1;
}
diff --git a/src/state.c b/src/state.c
index da065a5..010210e 100644
--- a/src/state.c
+++ b/src/state.c
@@ -16,12 +16,7 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
state->run = true;
state->resolution = (Vector2){ 800, 600 };
state->luaState = NULL;
- state->guiFont = 0;
state->logLevelInvalid = LOG_ERROR;
- /* Fonts. */
- state->fontAlloc = ALLOC_PAGE_SIZE;
- state->fontCount = 1;
- state->fonts = malloc( state->fontAlloc * sizeof( Font* ) );
/* Waves. */
state->waveAlloc = ALLOC_PAGE_SIZE;
state->waveCount = 0;
@@ -65,7 +60,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
/* The ones we want to save the first. */
if ( 0 < i ) {
- state->fonts[i] = NULL;
state->materials[i] = NULL;
}
}
@@ -73,8 +67,6 @@ bool stateInit( int argn, const char **argc, const char *exePath ) {
/* Has to be after InitWindod where opengl context is created. */
state->materials[0] = malloc( sizeof( Material ) );
*state->materials[0] = LoadMaterialDefault();
- state->fonts[0] = malloc( sizeof( Font ) );
- *state->fonts[0] = GetFontDefault();
if ( !IsWindowReady() ) {
state->hasWindow = false;
@@ -94,12 +86,6 @@ void stateInitInterpret( int argn, const char **argc ) {
}
void stateFree() {
- for ( int i = 0; i < state->fontCount; ++i ) {
- if ( state->fonts[i] != NULL ) {
- UnloadFont( *state->fonts[i] );
- free( state->fonts[i] );
- }
- }
for ( int i = 0; i < state->waveCount; ++i ) {
if ( state->waves[i] != NULL ) {
UnloadWave( *state->waves[i] );
@@ -165,7 +151,6 @@ void stateFree() {
if ( state->hasWindow ) {
CloseWindow();
}
- free( state->fonts );
free( state->waves );
free( state->sounds );
free( state->musics );
diff --git a/src/text.c b/src/text.c
index 1d6b464..75ff06b 100644
--- a/src/text.c
+++ b/src/text.c
@@ -4,103 +4,77 @@
#include "textures.h"
#include "lua_core.h"
-static void checkFontRealloc( int i ) {
- if ( i == state->fontCount ) {
- state->fontCount++;
- }
-
- if ( state->fontCount == state->fontAlloc ) {
- state->fontAlloc += ALLOC_PAGE_SIZE;
- state->fonts = realloc( state->fonts, state->fontAlloc * sizeof( Font* ) );
-
- for ( i = state->fontCount; i < state->fontAlloc; i++ ) {
- state->fonts[i] = NULL;
- }
- }
-}
-
-bool validFont( size_t id ) {
- if ( id < 0 || state->fontCount < id || state->fonts[ id ] == NULL ) {
- TraceLog( state->logLevelInvalid, "%s %d", "Invalid font", id );
- return false;
- }
- else {
- return true;
- }
-}
+/*
+## Text - Loading
+*/
-static int newFont() {
- int i = 0;
+/*
+> RL.GetFontDefault()
- for ( i = 0; i < state->fontCount; i++ ) {
- if ( state->fonts[i] == NULL ) {
- break;
- }
- }
- state->fonts[i] = malloc( sizeof( Font ) );
- checkFontRealloc( i );
+Get the default Font
+*/
+int ltextGetFontDefault( lua_State *L ) {
+ uluaPushFont( L, GetFontDefault() );
- return i;
+ return 1;
}
/*
-## Text - Loading
-*/
-
-/*
> font = RL.LoadFont( string fileName )
-Load font from file into GPU memory ( VRAM )
+Load font from file into GPU memory (VRAM)
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Font
*/
int ltextLoadFont( lua_State *L ) {
- if ( !lua_isstring( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadFont( string fileName )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- if ( FileExists( lua_tostring( L, 1 ) ) ) {
- int i = newFont();
- *state->fonts[i] = LoadFont( lua_tostring( L, 1 ) );
- lua_pushinteger( L, i );
- return 1;
- }
- else {
- lua_pushinteger( L, -1 );
+ if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
+ uluaPushFont( L, LoadFont( lua_tostring( L, 1 ) ) );
+
return 1;
}
+ TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
+ lua_pushnil( L );
return 1;
}
/*
-> font = RL.LoadFontEx( string fileName, int fontSize )
+> font = RL.LoadFontEx( string fileName, int fontSize, int fontChars{} )
Load font from file with extended parameters. Loading the default character set
-- Failure return -1
-- Success return int
+- Failure return nil
+- Success return Font
*/
int ltextLoadFontEx( lua_State *L ) {
- if ( !lua_isstring( L, 1 ) || !lua_isnumber( L, 2 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.LoadFontEx( string fileName, int fontSize )" );
- lua_pushinteger( L, -1 );
- return 1;
- }
- int fontSize = lua_tointeger( L, 2 );
+ int fontSize = luaL_checkinteger( L, 2 );
+
+ if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
+ if ( lua_istable( L, 3 ) ) {
+ int glyphCount = uluaGetTableLenIndex( L, 3 );
+ int fontChars[ glyphCount ];
+
+ int t = lua_gettop( L );
+ int i = 0;
+ lua_pushnil( L );
+
+ while ( lua_next( L, t ) != 0 ) {
+ fontChars[i] = lua_tointeger( L, -1 );
+
+ i++;
+ lua_pop( L, 1 );
+ }
+ uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, fontChars, glyphCount ) );
+
+ return 0;
+ }
+ uluaPushFont( L, LoadFontEx( lua_tostring( L, 1 ), fontSize, NULL, 0 ) );
- if ( FileExists( lua_tostring( L, 1 ) ) ) {
- int i = newFont();
- *state->fonts[i] = LoadFontEx( lua_tostring( L, 1 ), fontSize, NULL, 0 );
- lua_pushinteger( L, i );
- return 1;
- }
- else {
- lua_pushinteger( L, -1 );
return 1;
}
+ TraceLog( state->logLevelInvalid, "Invalid file path '%s'", lua_tostring( L, 1 ) );
+ lua_pushnil( L );
return 1;
}
@@ -110,44 +84,14 @@ int ltextLoadFontEx( lua_State *L ) {
Load font from Image ( XNA style )
-- Failure return -1
-- Success return int
+- Success return Font
*/
int ltextLoadFontFromImage( lua_State *L ) {
Image *image = luaL_checkudata( L, 1, "Image" );
Color key = uluaGetColorIndex( L, 2 );
- int firstChar = lua_tointeger( L, 3 );
-
- int i = newFont();
- *state->fonts[i] = LoadFontFromImage( *image, key, firstChar );
- lua_pushinteger( L, i );
-
- return 1;
-}
-
-/*
-> success = RL.UnloadFont( Font font )
-
-Unload Font from GPU memory ( VRAM )
+ int firstChar = luaL_checkinteger( L, 3 );
-- Failure return false
-- Success return true
-*/
-int ltextUnloadFont( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.UnloadFont( Font font )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t FontId = lua_tointeger( L, 1 );
-
- if ( !validFont( FontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- UnloadFont( *state->fonts[ FontId ] );
- state->fonts[ FontId ] = NULL;
- lua_pushboolean( L, true );
+ uluaPushFont( L, LoadFontFromImage( *image, key, firstChar ) );
return 1;
}
@@ -157,89 +101,52 @@ int ltextUnloadFont( lua_State *L ) {
*/
/*
-> success = RL.DrawFPS( Vector2 pos )
+> RL.DrawFPS( Vector2 pos )
Draw current FPS
-
-- Failure return false
-- Success return true
*/
int ltextDrawFPS( lua_State *L ) {
- if ( !lua_istable( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawFPS( Vector2 pos )" );
- lua_pushboolean( L, false );
- return 1;
- }
Vector2 pos = uluaGetVector2Index( L, 1 );
DrawFPS( pos.x, pos.y );
- lua_pushboolean( L, true );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
+> RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )
Draw text using font and additional parameters
-
-- Failure return false
-- Success return true
*/
int ltextDrawText( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 )
- || !lua_isnumber( L, 4 ) || !lua_isnumber( L, 5 ) || !lua_istable( L, 6 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawText( Font font, string text, Vector2 position, float fontSize, float spacing, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
+ Font *font = luaL_checkudata( L, 1, "Font" );
Vector2 position = uluaGetVector2Index( L, 3 );
- float fontSize = lua_tonumber( L, 4 );
- float spacing = lua_tonumber( L, 5 );
+ float fontSize = luaL_checknumber( L, 4 );
+ float spacing = luaL_checknumber( L, 5 );
Color tint = uluaGetColorIndex( L, 6 );
- if ( !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- DrawTextEx( *state->fonts[ fontId ], lua_tostring( L, 2 ), position, fontSize, spacing, tint );
- lua_pushboolean( L, true );
+ DrawTextEx( *font, luaL_checkstring( L, 2 ), position, fontSize, spacing, tint );
- return 1;
+ return 0;
}
/*
-> success = RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
+> RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )
-Draw text using Font and pro parameters ( rotation )
-
-- Failure return false
-- Success return true
+Draw text using Font and pro parameters (rotation)
*/
int ltextDrawTextPro( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_istable( L, 3 ) || !lua_istable( L, 4 )
- || !lua_isnumber( L, 5 ) || !lua_isnumber( L, 6 ) || !lua_isnumber( L, 7 ) || !lua_istable( L, 8 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.DrawTextPro( Font font, string text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
+ Font *font = luaL_checkudata( L, 1, "Font" );
Vector2 position = uluaGetVector2Index( L, 3 );
Vector2 origin = uluaGetVector2Index( L, 4 );
- float rotation = lua_tonumber( L, 5 );
- float fontSize = lua_tonumber( L, 6 );
- float spacing = lua_tonumber( L, 7 );
+ float rotation = luaL_checknumber( L, 5 );
+ float fontSize = luaL_checknumber( L, 6 );
+ float spacing = luaL_checknumber( L, 7 );
Color tint = uluaGetColorIndex( L, 8 );
- if ( !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- DrawTextPro( *state->fonts[ fontId ], lua_tostring( L, 2 ), position, origin, rotation, fontSize, spacing, tint );
- lua_pushboolean( L, true );
+ DrawTextPro( *font, luaL_checkstring( L, 2 ), position, origin, rotation, fontSize, spacing, tint );
- return 1;
+ return 0;
}
/*
@@ -251,24 +158,14 @@ int ltextDrawTextPro( lua_State *L ) {
Measure string size for Font
-- Failure return false
- Success return Vector2
*/
int ltextMeasureText( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) || !lua_isstring( L, 2 ) || !lua_isnumber( L, 3 ) || !lua_isnumber( L, 4 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.MeasureText( Font font, string text, float fontSize, float spacing )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
- float fontSize = lua_tonumber( L, 3 );
- float spacing = lua_tonumber( L, 4 );
+ Font *font = luaL_checkudata( L, 1, "Font" );
+ float fontSize = luaL_checknumber( L, 3 );
+ float spacing = luaL_checknumber( L, 4 );
- if ( !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushVector2( L, MeasureTextEx( *state->fonts[ fontId ], lua_tostring( L, 2 ), fontSize, spacing ) );
+ uluaPushVector2( L, MeasureTextEx( *font, luaL_checkstring( L, 2 ), fontSize, spacing ) );
return 1;
}
@@ -276,24 +173,14 @@ int ltextMeasureText( lua_State *L ) {
/*
> baseSize = RL.GetFontBaseSize( Font font )
-Get font base size ( default chars height )
+Get font base size (default chars height)
-- Failure return false
- Success return int
*/
int ltextGetFontBaseSize( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetFontBaseSize( Font font )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
+ Font *font = luaL_checkudata( L, 1, "Font" );
- if ( !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->fonts[ fontId ]->baseSize );
+ lua_pushinteger( L, font->baseSize );
return 1;
}
@@ -303,22 +190,12 @@ int ltextGetFontBaseSize( lua_State *L ) {
Get font number of glyph characters
-- Failure return false
- Success return int
*/
int ltextGetFontGlyphCount( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetFontGlyphCount( Font font )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
+ Font *font = luaL_checkudata( L, 1, "Font" );
- if ( !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->fonts[ fontId ]->glyphCount );
+ lua_pushinteger( L, font->glyphCount );
return 1;
}
@@ -328,47 +205,27 @@ int ltextGetFontGlyphCount( lua_State *L ) {
Get font padding around the glyph characters
-- Failure return false
- Success return int
*/
int ltextGetFontGlyphPadding( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetFontGlyphPadding( Font font )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
+ Font *font = luaL_checkudata( L, 1, "Font" );
- if ( !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- lua_pushinteger( L, state->fonts[ fontId ]->glyphPadding );
+ lua_pushinteger( L, font->glyphPadding );
return 1;
}
/*
-> textureTable = RL.GetFontTexture( Font font )
+> texture = RL.GetFontTexture( Font font )
-Get font texture atlas containing the glyphs. NOTE! Texture in table form.
+Get font texture atlas containing the glyphs.
-- Failure return false
-- Success return table
+- Success return Texture
*/
int ltextGetFontTexture( lua_State *L ) {
- if ( !lua_isnumber( L, 1 ) ) {
- TraceLog( state->logLevelInvalid, "%s", "Bad call of function. RL.GetFontTexture( Font font )" );
- lua_pushboolean( L, false );
- return 1;
- }
- size_t fontId = lua_tointeger( L, 1 );
+ Font *font = luaL_checkudata( L, 1, "Font" );
- if ( !validFont( fontId ) ) {
- lua_pushboolean( L, false );
- return 1;
- }
- uluaPushTexture( L, state->fonts[ fontId ]->texture );
+ uluaPushTexture( L, font->texture );
return 1;
}
diff --git a/src/textures.c b/src/textures.c
index 28cb1cb..2121d12 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -924,7 +924,7 @@ Load texture from file into GPU memory ( VRAM )
- Success return Texture
*/
int ltexturesLoadTexture( lua_State *L ) {
- if ( FileExists( lua_tostring( L, 1 ) ) ) {
+ if ( FileExists( luaL_checkstring( L, 1 ) ) ) {
uluaPushTexture( L, LoadTexture( lua_tostring( L, 1 ) ) );
return 1;