From af03c7364ea0dfe2c8bb269eb8a8f9b580f39633 Mon Sep 17 00:00:00 2001 From: jussi Date: Sat, 28 Oct 2023 14:15:20 +0300 Subject: New object type Font. --- src/lua_core.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/lua_core.c') 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 ) ); } -- cgit v1.2.3