diff options
| -rw-r--r-- | API.md | 54 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | ReiLua_API.lua | 44 | ||||
| -rw-r--r-- | changelog | 3 | ||||
| -rw-r--r-- | examples/window/main.lua | 2 | ||||
| -rw-r--r-- | include/core.h | 7 | ||||
| -rw-r--r-- | src/core.c | 111 | ||||
| -rw-r--r-- | src/lua_core.c | 7 | ||||
| -rw-r--r-- | src/platforms/core_desktop.c | 162 | ||||
| -rw-r--r-- | src/platforms/core_web.c | 1 | ||||
| -rw-r--r-- | src/text.c | 4 |
11 files changed, 272 insertions, 125 deletions
@@ -4220,6 +4220,50 @@ Set Lua garbage collection to unload object data --- +> buffer = RL.LoadFileData( string fileName ) + +Load file data as byte array (read). Buffer type is BUFFER_UNSIGNED_CHAR + +- Success return Buffer + +--- + +> success = RL.SaveFileData( string fileName, buffer Buffer ) + +Save data to file from byte array (write), returns true on success + +- Success return bool + +--- + +> success = RL.ExportDataAsCode( Buffer buffer, string fileName ) + +Export data to code (.h), returns true on success + +- Success return bool + +--- + +> text = RL.LoadFileText( string fileName ) + +Load text data from file (read) + +- Success return string + +--- + +> success = RL.SaveFileText( string fileName, string text ) + +Save text data to file (write), returns true on success + +- Success return bool + +--- + +## Core - Files system functions + +--- + > path = RL.GetBasePath() Return game directory (where main.lua is located) @@ -4995,7 +5039,7 @@ Unload buffer data > data = RL.GetBufferData( Buffer buffer ) -Get buffer data as table in the format is was stored +Get buffer data as table in the format it was stored - Success return data{} @@ -5023,14 +5067,6 @@ Write buffer data to binary file --- -> success = RL.ExportBufferAsCode( Buffer buffer, string fileName ) - -Export buffer data to code (.h), returns true on success - -- Success return bool - ---- - ## Shapes - Basic shapes drawing functions --- @@ -58,7 +58,7 @@ end function RL.draw() RL.ClearBackground( RL.RAYWHITE ) - RL.DrawText( RL.GetFontDefault(), "Congrats! You created your first window!", textPos, 20, 2, textColor ) + RL.DrawText( RL.GetFontDefault(), "Congrats! You created your first window!", textPos, 20, 2, textColor ) end ``` diff --git a/ReiLua_API.lua b/ReiLua_API.lua index baccf5e..73217f9 100644 --- a/ReiLua_API.lua +++ b/ReiLua_API.lua @@ -1774,6 +1774,41 @@ function RL.SetGCUnload( enabled ) end -- Core - Files management functions +---Load file data as byte array (read). Buffer type is BUFFER_UNSIGNED_CHAR +---- Success return Buffer +---@param fileName string +---@return any buffer +function RL.LoadFileData( fileName ) end + +---Save data to file from byte array (write), returns true on success +---- Success return bool +---@param fileName string +---@param Buffer any +---@return any success +function RL.SaveFileData( fileName, Buffer ) end + +---Export data to code (.h), returns true on success +---- Success return bool +---@param buffer any +---@param fileName string +---@return any success +function RL.ExportDataAsCode( buffer, fileName ) end + +---Load text data from file (read) +---- Success return string +---@param fileName string +---@return any text +function RL.LoadFileText( fileName ) end + +---Save text data to file (write), returns true on success +---- Success return bool +---@param fileName string +---@param text string +---@return any success +function RL.SaveFileText( fileName, text ) end + +-- Core - Files system functions + ---Return game directory (where main.lua is located) ---- Success return string ---@return any path @@ -2379,7 +2414,7 @@ function RL.LoadBufferFromFile( path, int ) end ---@return any RL.UnloadBuffer function RL.UnloadBuffer( buffer ) end ----Get buffer data as table in the format is was stored +---Get buffer data as table in the format it was stored ---- Success return data{} ---@param buffer any ---@return any data @@ -2403,13 +2438,6 @@ function RL.GetBufferSize( buffer ) end ---@return any RL.ExportBuffer function RL.ExportBuffer( buffer, path ) end ----Export buffer data to code (.h), returns true on success ----- Success return bool ----@param buffer any ----@param fileName string ----@return any success -function RL.ExportBufferAsCode( buffer, fileName ) end - -- Shapes - Basic shapes drawing functions ---Set texture and rectangle to be used on shapes drawing @@ -19,6 +19,7 @@ KEY CHANGES: - ADDED: Raygui textures with SetShapesTexture. - CHANGE: Raygui wrapper library is now object based. Possible to have multiple separated gui systems. - ADDED: Raygui wrapper library disabled and styles for each element. + - ADDED: Files management functions. DETAILED CHANGES: - REMOVED: DrawLineBezierQuad, DrawLineBezierCubic. @@ -36,6 +37,8 @@ DETAILED CHANGES: - CHANGE: Event documentation is now described in c files. - ADDED: ExportBufferAsCode. - ADDED: GetTextureDefault. + - CHANGE: Renamed Files management functions to Files system functions as in raylib. + - CHANGE: Renamed ExportBufferAsCode to ExportDataAsCode. ------------------------------------------------------------------------ Release: ReiLua version 0.6.0 Using Raylib 4.5 diff --git a/examples/window/main.lua b/examples/window/main.lua index 808cccc..63c18d7 100644 --- a/examples/window/main.lua +++ b/examples/window/main.lua @@ -25,6 +25,4 @@ end function RL.draw() RL.ClearBackground( RL.RAYWHITE ) RL.DrawText( text, textPos, 20, textColor ) - - RL.DrawCircle( { 300, 300 }, 180, RL.BLACK ) end diff --git a/include/core.h b/include/core.h index ff657e6..5103cb8 100644 --- a/include/core.h +++ b/include/core.h @@ -108,6 +108,12 @@ int lcoreOpenURL( lua_State *L ); int lcoreIsGCUnloadEnabled( lua_State *L ); int lcoreSetGCUnload( lua_State *L ); /* Files management functions. */ +int lcoreLoadFileData( lua_State *L ); +int lcoreSaveFileData( lua_State *L ); +int lcoreExportDataAsCode( lua_State *L ); +int lcoreLoadFileText( lua_State *L ); +int lcoreSaveFileText( lua_State *L ); +/* Files system functions. */ int lcoreGetBasePath( lua_State *L ); int lcoreFileExists( lua_State *L ); int lcoreDirectoryExists( lua_State *L ); @@ -220,4 +226,3 @@ int lcoreGetBufferData( lua_State *L ); int lcoreGetBufferType( lua_State *L ); int lcoreGetBufferSize( lua_State *L ); int lcoreExportBuffer( lua_State *L ); -int lcoreExportBufferAsCode( lua_State *L ); @@ -1419,6 +1419,95 @@ int lcoreSetGCUnload( lua_State *L ) { */ /* +> buffer = RL.LoadFileData( string fileName ) + +Load file data as byte array (read). Buffer type is BUFFER_UNSIGNED_CHAR + +- Success return Buffer +*/ +int lcoreLoadFileData( lua_State *L ) { + const char *fileName = luaL_checkstring( L, 1 ); + + Buffer buffer = { + .type = BUFFER_UNSIGNED_CHAR + }; + buffer.data = LoadFileData( fileName, (int*)&buffer.size ); + + uluaPushBuffer( L, buffer ); + + return 1; +} + +/* +> success = RL.SaveFileData( string fileName, buffer Buffer ) + +Save data to file from byte array (write), returns true on success + +- Success return bool +*/ +int lcoreSaveFileData( lua_State *L ) { + const char *fileName = luaL_checkstring( L, 1 ); + Buffer *buffer = uluaGetBuffer( L, 2 ); + + lua_pushboolean( L, SaveFileData( fileName, buffer->data, buffer->size ) ); + + return 1; +} + +/* +> success = RL.ExportDataAsCode( Buffer buffer, string fileName ) + +Export data to code (.h), returns true on success + +- Success return bool +*/ +int lcoreExportDataAsCode( lua_State *L ) { + Buffer *buffer = uluaGetBuffer( L, 1 ); + const char *fileName = luaL_checkstring( L, 2 ); + + lua_pushboolean( L, ExportDataAsCode( buffer->data, buffer->size, fileName ) ); + + return 1; +} + +/* +> text = RL.LoadFileText( string fileName ) + +Load text data from file (read) + +- Success return string +*/ +int lcoreLoadFileText( lua_State *L ) { + const char *fileName = luaL_checkstring( L, 1 ); + + char *text = LoadFileText( fileName ); + lua_pushstring( L, text ); + UnloadFileText( text ); + + return 1; +} + +/* +> success = RL.SaveFileText( string fileName, string text ) + +Save text data to file (write), returns true on success + +- Success return bool +*/ +int lcoreSaveFileText( lua_State *L ) { + const char *fileName = luaL_checkstring( L, 1 ); + char *text = (char*)luaL_checkstring( L, 2 ); + + lua_pushboolean( L, SaveFileText( fileName, text ) ); + + return 1; +} + +/* +## Core - Files system functions +*/ + +/* > path = RL.GetBasePath() Return game directory (where main.lua is located) @@ -2951,8 +3040,8 @@ Read buffer data from binary file - Success return Buffer */ int lcoreLoadBufferFromFile( lua_State *L ) { - int type = luaL_checkinteger( L, 2 ); const char *path = luaL_checkstring( L, 1 ); + int type = luaL_checkinteger( L, 2 ); int fileLen = GetFileLength( path ); Buffer buffer = { @@ -2993,7 +3082,7 @@ int lcoreUnloadBuffer( lua_State *L ) { /* > data = RL.GetBufferData( Buffer buffer ) -Get buffer data as table in the format is was stored +Get buffer data as table in the format it was stored - Success return data{} */ @@ -3135,24 +3224,8 @@ int lcoreExportBuffer( lua_State *L ) { FILE *file; file = fopen( path, "wb" ); - fwrite( buffer->data, elementSize, buffer->size / elementSize, file ) ; + fwrite( buffer->data, elementSize, buffer->size / elementSize, file ); fclose( file ); return 0; } - -/* -> success = RL.ExportBufferAsCode( Buffer buffer, string fileName ) - -Export buffer data to code (.h), returns true on success - -- Success return bool -*/ -int lcoreExportBufferAsCode( lua_State *L ) { - Buffer *buffer = uluaGetBuffer( L, 1 ); - const char *fileName = luaL_checkstring( L, 2 ); - - lua_pushboolean( L, ExportDataAsCode( buffer->data, buffer->size, fileName ) ); - - return 1; -} diff --git a/src/lua_core.c b/src/lua_core.c index ecd5f75..acd4ac7 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1264,6 +1264,12 @@ void luaRegister() { assingGlobalFunction( "IsGCUnloadEnabled", lcoreIsGCUnloadEnabled ); assingGlobalFunction( "SetGCUnload", lcoreSetGCUnload ); /* Files management functions. */ + assingGlobalFunction( "LoadFileData", lcoreLoadFileData ); + assingGlobalFunction( "SaveFileData", lcoreSaveFileData ); + assingGlobalFunction( "ExportDataAsCode", lcoreExportDataAsCode ); + assingGlobalFunction( "LoadFileText", lcoreLoadFileText ); + assingGlobalFunction( "SaveFileText", lcoreSaveFileText ); + /* Files system functions. */ assingGlobalFunction( "GetBasePath", lcoreGetBasePath ); assingGlobalFunction( "FileExists", lcoreFileExists ); assingGlobalFunction( "DirectoryExists", lcoreDirectoryExists ); @@ -1374,7 +1380,6 @@ void luaRegister() { assingGlobalFunction( "GetBufferType", lcoreGetBufferType ); assingGlobalFunction( "GetBufferSize", lcoreGetBufferSize ); assingGlobalFunction( "ExportBuffer", lcoreExportBuffer ); - assingGlobalFunction( "ExportBufferAsCode", lcoreExportBufferAsCode ); /* Shapes. */ /* Basic shapes drawing functions. */ diff --git a/src/platforms/core_desktop.c b/src/platforms/core_desktop.c index d2c595e..fa47d4a 100644 --- a/src/platforms/core_desktop.c +++ b/src/platforms/core_desktop.c @@ -519,41 +519,41 @@ static void joystickEvent( int jid, int event ) { Called when the pen tablet data is updated. Type GLFW_PEN_TABLET_DATA_EVENT NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 */ -// static void penTabletDataEvent( double x, double y, double z, double pressure, double pitch, double yaw, double roll ) { -// lua_State *L = state->luaState; - -// lua_pushcfunction( L, luaTraceback ); -// int tracebackidx = lua_gettop( L ); - -// lua_getglobal( L, "RL" ); -// lua_getfield( L, -1, "event" ); - -// if ( lua_isfunction( L, -1 ) ) { -// lua_createtable( L, 8, 0 ); -// lua_pushinteger( L, GLFW_PEN_TABLET_DATA_EVENT ); -// lua_setfield( L, -2, "type" ); -// lua_pushnumber( L, x ); -// lua_setfield( L, -2, "x" ); -// lua_pushnumber( L, y ); -// lua_setfield( L, -2, "y" ); -// lua_pushnumber( L, z ); -// lua_setfield( L, -2, "z" ); -// lua_pushnumber( L, pressure ); -// lua_setfield( L, -2, "pressure" ); -// lua_pushnumber( L, pitch ); -// lua_setfield( L, -2, "pitch" ); -// lua_pushnumber( L, yaw ); -// lua_setfield( L, -2, "yaw" ); -// lua_pushnumber( L, roll ); -// lua_setfield( L, -2, "roll" ); - -// if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { -// TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); -// state->run = false; -// } -// } -// lua_pop( L, -1 ); -// } +static void penTabletDataEvent( double x, double y, double z, double pressure, double pitch, double yaw, double roll ) { + lua_State *L = state->luaState; + + lua_pushcfunction( L, luaTraceback ); + int tracebackidx = lua_gettop( L ); + + lua_getglobal( L, "RL" ); + lua_getfield( L, -1, "event" ); + + if ( lua_isfunction( L, -1 ) ) { + lua_createtable( L, 8, 0 ); + lua_pushinteger( L, GLFW_PEN_TABLET_DATA_EVENT ); + lua_setfield( L, -2, "type" ); + lua_pushnumber( L, x ); + lua_setfield( L, -2, "x" ); + lua_pushnumber( L, y ); + lua_setfield( L, -2, "y" ); + lua_pushnumber( L, z ); + lua_setfield( L, -2, "z" ); + lua_pushnumber( L, pressure ); + lua_setfield( L, -2, "pressure" ); + lua_pushnumber( L, pitch ); + lua_setfield( L, -2, "pitch" ); + lua_pushnumber( L, yaw ); + lua_setfield( L, -2, "yaw" ); + lua_pushnumber( L, roll ); + lua_setfield( L, -2, "roll" ); + + if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { + TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); + state->run = false; + } + } + lua_pop( L, -1 ); +} /* > GLFWpentabletcursorEvent = { int type, int identifier } @@ -561,29 +561,29 @@ NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 Called when the pen tablet cursor has changed. Type GLFW_PEN_TABLET_CURSOR_EVENT NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 */ -// static void penTabletCursorEvent( unsigned int identifier ) { -// lua_State *L = state->luaState; - -// lua_pushcfunction( L, luaTraceback ); -// int tracebackidx = lua_gettop( L ); - -// lua_getglobal( L, "RL" ); -// lua_getfield( L, -1, "event" ); - -// if ( lua_isfunction( L, -1 ) ) { -// lua_createtable( L, 2, 0 ); -// lua_pushinteger( L, GLFW_PEN_TABLET_CURSOR_EVENT ); -// lua_setfield( L, -2, "type" ); -// lua_pushinteger( L, identifier ); -// lua_setfield( L, -2, "identifier" ); - -// if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { -// TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); -// state->run = false; -// } -// } -// lua_pop( L, -1 ); -// } +static void penTabletCursorEvent( unsigned int identifier ) { + lua_State *L = state->luaState; + + lua_pushcfunction( L, luaTraceback ); + int tracebackidx = lua_gettop( L ); + + lua_getglobal( L, "RL" ); + lua_getfield( L, -1, "event" ); + + if ( lua_isfunction( L, -1 ) ) { + lua_createtable( L, 2, 0 ); + lua_pushinteger( L, GLFW_PEN_TABLET_CURSOR_EVENT ); + lua_setfield( L, -2, "type" ); + lua_pushinteger( L, identifier ); + lua_setfield( L, -2, "identifier" ); + + if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { + TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); + state->run = false; + } + } + lua_pop( L, -1 ); +} /* > GLFWpentabletproximityEvent = { int type, int proxState } @@ -591,29 +591,29 @@ NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 Called when the pen tablet proximity has changed. Type GLFW_PEN_TABLET_PROXIMITY_EVENT NOTE! Experimental. Needs glfw PR https://github.com/glfw/glfw/pull/1445 */ -// static void penTabletProximityEvent( int proxState ) { -// lua_State *L = state->luaState; - -// lua_pushcfunction( L, luaTraceback ); -// int tracebackidx = lua_gettop( L ); - -// lua_getglobal( L, "RL" ); -// lua_getfield( L, -1, "event" ); - -// if ( lua_isfunction( L, -1 ) ) { -// lua_createtable( L, 2, 0 ); -// lua_pushinteger( L, GLFW_PEN_TABLET_PROXIMITY_EVENT ); -// lua_setfield( L, -2, "type" ); -// lua_pushinteger( L, proxState ); -// lua_setfield( L, -2, "state" ); - -// if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { -// TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); -// state->run = false; -// } -// } -// lua_pop( L, -1 ); -// } +static void penTabletProximityEvent( int proxState ) { + lua_State *L = state->luaState; + + lua_pushcfunction( L, luaTraceback ); + int tracebackidx = lua_gettop( L ); + + lua_getglobal( L, "RL" ); + lua_getfield( L, -1, "event" ); + + if ( lua_isfunction( L, -1 ) ) { + lua_createtable( L, 2, 0 ); + lua_pushinteger( L, GLFW_PEN_TABLET_PROXIMITY_EVENT ); + lua_setfield( L, -2, "type" ); + lua_pushinteger( L, proxState ); + lua_setfield( L, -2, "state" ); + + if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) { + TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); + state->run = false; + } + } + lua_pop( L, -1 ); +} static void platformRegisterEvents() { /* Window events. */ diff --git a/src/platforms/core_web.c b/src/platforms/core_web.c index 24d3bf2..2cf255a 100644 --- a/src/platforms/core_web.c +++ b/src/platforms/core_web.c @@ -16,5 +16,4 @@ void platformDefineGlobals() { /* Events. */ void luaPlatformRegister() { - return; } @@ -19,7 +19,7 @@ bool wordWrap, Color *tints, int tintCount, Color *backTints, int backTintCount // Word/character wrapping mechanism variables enum { MEASURE_STATE = 0, DRAW_STATE = 1 }; - int state = wordWrap? MEASURE_STATE : DRAW_STATE; + int state = wordWrap ? MEASURE_STATE : DRAW_STATE; int startLine = -1; // Index where to begin drawing (where a line begins) int endLine = -1; // Index where to stop drawing (where a line ends) @@ -29,7 +29,7 @@ bool wordWrap, Color *tints, int tintCount, Color *backTints, int backTintCount Vector2 mousePos = GetMousePosition(); int mouseChar = -1; - for (int i = 0, k = 0; i < length; i++, k++) + for ( int i = 0, k = 0; i < length; i++, k++) { if ( i < tintCount ) { tint = tints[i]; |
