From afa9f711a8ee734be0de17f81a65bf6a18931439 Mon Sep 17 00:00:00 2001 From: Lu <204598839+lucenthropic@users.noreply.github.com> Date: Mon, 15 Sep 2025 12:06:30 -0400 Subject: [PATCH] Add love.system.getMemorySize --- changes.txt | 1 + src/modules/system/System.h | 5 +++++ src/modules/system/sdl/System.cpp | 5 +++++ src/modules/system/sdl/System.h | 1 + src/modules/system/wrap_System.cpp | 7 +++++++ testing/tests/system.lua | 6 ++++++ 6 files changed, 25 insertions(+) diff --git a/changes.txt b/changes.txt index 3835e99b9..5d20dc20b 100644 --- a/changes.txt +++ b/changes.txt @@ -81,6 +81,7 @@ Released: N/A * Added love.sensorupdated callback. * Added love.joysticksensorupdated callback. * Added variant for enet peer:send and host:broadcast which accepts a pointer (light userdata) and a size. +* Added love.system.getMemorySize. * Changed the default font from Vera size 12 to Noto Sans size 13. * Changed TrueType and OpenType font handling to have improved kerning and character combining support. diff --git a/src/modules/system/System.h b/src/modules/system/System.h index cf71fae03..143fe8969 100644 --- a/src/modules/system/System.h +++ b/src/modules/system/System.h @@ -63,6 +63,11 @@ public: **/ virtual int getProcessorCount() const = 0; + /** + * Gets the amount of RAM configured in the system in MiB. + **/ + virtual int getMemorySize() const = 0; + /** * Replaces the contents of the system's text clipboard with a string. * @param text The clipboard text to set. diff --git a/src/modules/system/sdl/System.cpp b/src/modules/system/sdl/System.cpp index c417f0791..be5fde78c 100644 --- a/src/modules/system/sdl/System.cpp +++ b/src/modules/system/sdl/System.cpp @@ -45,6 +45,11 @@ int System::getProcessorCount() const return SDL_GetNumLogicalCPUCores(); } +int System::getMemorySize() const +{ + return SDL_GetSystemRAM(); +} + bool System::isWindowOpen() const { auto window = Module::getInstance(M_WINDOW); diff --git a/src/modules/system/sdl/System.h b/src/modules/system/sdl/System.h index 3f40b506a..a296d1111 100644 --- a/src/modules/system/sdl/System.h +++ b/src/modules/system/sdl/System.h @@ -43,6 +43,7 @@ public: virtual ~System() {} int getProcessorCount() const override; + int getMemorySize() const override; void setClipboardText(const std::string &text) const override; std::string getClipboardText() const override; diff --git a/src/modules/system/wrap_System.cpp b/src/modules/system/wrap_System.cpp index 8633d805a..4fcdf1389 100644 --- a/src/modules/system/wrap_System.cpp +++ b/src/modules/system/wrap_System.cpp @@ -41,6 +41,12 @@ int w_getProcessorCount(lua_State *L) return 1; } +int w_getMemorySize(lua_State *L) +{ + lua_pushinteger(L, instance()->getMemorySize()); + return 1; +} + int w_setClipboardText(lua_State *L) { const char *text = luaL_checkstring(L, 1); @@ -121,6 +127,7 @@ static const luaL_Reg functions[] = { { "getOS", w_getOS }, { "getProcessorCount", w_getProcessorCount }, + { "getMemorySize", w_getMemorySize }, { "setClipboardText", w_setClipboardText }, { "getClipboardText", w_getClipboardText }, { "getPowerInfo", w_getPowerInfo }, diff --git a/testing/tests/system.lua b/testing/tests/system.lua index 88912d525..fed0afd44 100644 --- a/testing/tests/system.lua +++ b/testing/tests/system.lua @@ -59,6 +59,12 @@ love.test.system.getProcessorCount = function(test) end +-- love.system.getMemorySize +love.test.system.getMemorySize = function(test) + test:assertNotNil(love.system.getMemorySize()) +end + + -- love.system.hasBackgroundMusic love.test.system.hasBackgroundMusic = function(test) test:assertNotNil(love.system.hasBackgroundMusic())