From dab9ba7b28946a8fcf4c7d92db6ef782ffcf2c95 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 12:17:24 -0700 Subject: [PATCH 01/15] Try accessing environment variable --- .github/workflows/docs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index ffda5489c..9e6436058 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -24,17 +24,17 @@ jobs: - name: Install dependencies run: npm install - working-directory: docs + working-directory: ${{ github.workspace }}/docs - name: Build docs site run: npm run build - working-directory: docs + working-directory: ${{ github.workspace }}/docs - name: Upload docs artifact id: deployment uses: actions/upload-pages-artifact@v3 with: - path: docs/.vitepress/dist/ + path: ${{ github.workspace }}/docs/.vitepress/dist/ deploy: runs-on: ubuntu-latest From 1d4f881b29438d82b35b2947bcfdd3562b218896 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 12:21:16 -0700 Subject: [PATCH 02/15] temp: only make this job run --- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0b1c8a19..e35d60e2f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,8 @@ name: CI on: push: branches: ["primary"] - pull_request: - branches: ["primary"] + # pull_request: + # branches: ["primary"] concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 9e6436058..bf242979f 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,6 +4,8 @@ on: push: branches: - primary + pull_request: + branches: ["primary"] jobs: build: From 58b14d2a793506bdb67f325e5a12a2d14b81c343 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 12:25:11 -0700 Subject: [PATCH 03/15] prints --- docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/package.json b/docs/package.json index 03fe8a475..560e18c9b 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "scripts": { - "gen": "lute run scripts/reference.luau", + "gen": "echo $PWD; echo $GITHUB_WORKSPACE; lute run scripts/reference.luau", "dev": "npm run gen && vitepress dev", "build": "npm run gen && vitepress build", "preview": "vitepress preview" From 602a3db944a53fdfb54e8a5f2ee99d18d5d75097 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 13:00:02 -0700 Subject: [PATCH 04/15] Incorporate real fix + undo hack --- .github/actions/setup-and-build/action.yml | 4 ---- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 6 +++--- lute/process/src/process.cpp | 6 +++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.github/actions/setup-and-build/action.yml b/.github/actions/setup-and-build/action.yml index 07ffa1ebf..def71560d 100644 --- a/.github/actions/setup-and-build/action.yml +++ b/.github/actions/setup-and-build/action.yml @@ -25,10 +25,6 @@ outputs: runs: using: "composite" steps: - - name: Set checkout path as LUTE_ROOT_DIR - shell: bash - run: echo "LUTE_ROOT_DIR=$(pwd)" >> $GITHUB_ENV - - name: Install tools uses: Roblox/setup-foreman@v3 with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e35d60e2f..d0b1c8a19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,8 @@ name: CI on: push: branches: ["primary"] - # pull_request: - # branches: ["primary"] + pull_request: + branches: ["primary"] concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bf242979f..7fa6057ae 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -26,17 +26,17 @@ jobs: - name: Install dependencies run: npm install - working-directory: ${{ github.workspace }}/docs + working-directory: $/docs - name: Build docs site run: npm run build - working-directory: ${{ github.workspace }}/docs + working-directory: docs - name: Upload docs artifact id: deployment uses: actions/upload-pages-artifact@v3 with: - path: ${{ github.workspace }}/docs/.vitepress/dist/ + path: docs/.vitepress/dist/ deploy: runs-on: ubuntu-latest diff --git a/lute/process/src/process.cpp b/lute/process/src/process.cpp index a3bb43cea..202781a1f 100644 --- a/lute/process/src/process.cpp +++ b/lute/process/src/process.cpp @@ -473,13 +473,13 @@ int cwd(lua_State* L) std::string buffer; size_t cwd_size = 255; - buffer.reserve(cwd_size); + buffer.resize(cwd_size); int status = uv_cwd(buffer.data(), &cwd_size); if (status == UV_ENOBUFS) { // libuv gives us the new size if it's under sized - buffer.reserve(cwd_size); + buffer.resize(cwd_size); status = uv_cwd(buffer.data(), &cwd_size); } @@ -490,7 +490,7 @@ int cwd(lua_State* L) return 1; } - lua_pushlstring(L, buffer.c_str(), buffer.size()); + lua_pushlstring(L, buffer.c_str(), cwd_size); return 1; }; From 9cc916340af8b9d68eb072d5ae3985ee48d57472 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 13:01:12 -0700 Subject: [PATCH 05/15] Fix typo --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7fa6057ae..be754592b 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: npm install - working-directory: $/docs + working-directory: docs - name: Build docs site run: npm run build From 801728fb13cac4e88c995eebeca8d27fcd63a53f Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 13:41:24 -0700 Subject: [PATCH 06/15] Abstract away buffer management --- lute/io/src/io.cpp | 2 +- lute/process/src/process.cpp | 53 ++++++----------------------- lute/runtime/CMakeLists.txt | 2 ++ lute/runtime/include/lute/uvutils.h | 20 +++++++++++ lute/runtime/src/uvutils.cpp | 29 ++++++++++++++++ lute/system/src/system.cpp | 48 +++++++------------------- 6 files changed, 74 insertions(+), 80 deletions(-) create mode 100644 lute/runtime/include/lute/uvutils.h create mode 100644 lute/runtime/src/uvutils.cpp diff --git a/lute/io/src/io.cpp b/lute/io/src/io.cpp index 2c7611188..b8ca486c4 100644 --- a/lute/io/src/io.cpp +++ b/lute/io/src/io.cpp @@ -2,7 +2,7 @@ #include "Luau/Variant.h" #include "lute/runtime.h" -#include +#include "uv.h" #include #include "lua.h" diff --git a/lute/process/src/process.cpp b/lute/process/src/process.cpp index 202781a1f..395cdeaa3 100644 --- a/lute/process/src/process.cpp +++ b/lute/process/src/process.cpp @@ -1,12 +1,13 @@ #include "lute/process.h" #include "lute/runtime.h" +#include "lute/uvutils.h" #include "Luau/Common.h" #include "lua.h" #include "lualib.h" -#include +#include "uv.h" #include #include @@ -432,28 +433,11 @@ int run(lua_State* L) int homedir(lua_State* L) { - std::string buffer; - - size_t homedir_size = 255; - buffer.reserve(homedir_size); - - int status = uv_os_homedir(buffer.data(), &homedir_size); - if (status == UV_ENOBUFS) - { - // libuv gives us the new size if it's under sized - buffer.reserve(homedir_size); - - status = uv_os_homedir(buffer.data(), &homedir_size); - } - - if (status != 0) - { - luaL_error(L, "failed to get home directory"); - return 1; - } - - lua_pushlstring(L, buffer.c_str(), buffer.size()); + uvutils::StringResult result = uvutils::getStringFromUv(uv_os_homedir); + if (result.status < 0) + luaL_error(L, "failed to get home directory: %s", uv_strerror(result.status)); + lua_pushlstring(L, result.value.c_str(), result.value.size()); return 1; } @@ -470,28 +454,11 @@ int exitFunc(lua_State* L) int cwd(lua_State* L) { - std::string buffer; - - size_t cwd_size = 255; - buffer.resize(cwd_size); - - int status = uv_cwd(buffer.data(), &cwd_size); - if (status == UV_ENOBUFS) - { - // libuv gives us the new size if it's under sized - buffer.resize(cwd_size); - - status = uv_cwd(buffer.data(), &cwd_size); - } - - if (status != 0) - { - luaL_error(L, "failed to get current working directory"); - return 1; - } - - lua_pushlstring(L, buffer.c_str(), cwd_size); + uvutils::StringResult result = uvutils::getStringFromUv(uv_cwd); + if (result.status < 0) + luaL_error(L, "failed to get current working directory: %s", uv_strerror(result.status)); + lua_pushlstring(L, result.value.c_str(), result.value.size()); return 1; }; diff --git a/lute/runtime/CMakeLists.txt b/lute/runtime/CMakeLists.txt index 0b4cfb7f7..839d88377 100644 --- a/lute/runtime/CMakeLists.txt +++ b/lute/runtime/CMakeLists.txt @@ -4,9 +4,11 @@ target_sources(Lute.Runtime PRIVATE include/lute/ref.h include/lute/runtime.h include/lute/userdatas.h + include/lute/uvutils.h src/ref.cpp src/runtime.cpp + src/uvutils.cpp ) target_compile_features(Lute.Runtime PUBLIC cxx_std_17) diff --git a/lute/runtime/include/lute/uvutils.h b/lute/runtime/include/lute/uvutils.h new file mode 100644 index 000000000..20c0a2169 --- /dev/null +++ b/lute/runtime/include/lute/uvutils.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +namespace uvutils +{ + +struct StringResult +{ + int status = 0; + std::string value; +}; + +typedef int (*BufferWriter)(char* buffer, size_t* size); + +// Abstracts away buffer management when getting strings from libuv functions. +StringResult getStringFromUv(BufferWriter bufferWriter, size_t initialBufferSize = 256); + +} // namespace uvutils diff --git a/lute/runtime/src/uvutils.cpp b/lute/runtime/src/uvutils.cpp new file mode 100644 index 000000000..295e7ceea --- /dev/null +++ b/lute/runtime/src/uvutils.cpp @@ -0,0 +1,29 @@ +#include "lute/uvutils.h" + +#include "uv.h" + +namespace uvutils +{ + +StringResult getStringFromUv(BufferWriter bufferWriter, size_t initialBufferSize) +{ + std::string buffer; + size_t size = initialBufferSize; + buffer.resize(size); + + int writeStatus = bufferWriter(buffer.data(), &size); + if (writeStatus == UV_ENOBUFS) + { + // `size` now contains the required size + buffer.resize(size); + writeStatus = bufferWriter(buffer.data(), &size); + } + + if (writeStatus < 0) + return StringResult{writeStatus, ""}; + + buffer.resize(size); + return StringResult{writeStatus, std::move(buffer)}; +} + +} // namespace uvutils diff --git a/lute/system/src/system.cpp b/lute/system/src/system.cpp index 247f33442..23e279b32 100644 --- a/lute/system/src/system.cpp +++ b/lute/system/src/system.cpp @@ -1,13 +1,16 @@ #include "lute/system.h" +#include "lute/uvutils.h" + #include "lua.h" #include "lualib.h" + #include "uv.h" + #include #include #include #include #include -#include namespace libsystem { @@ -88,24 +91,11 @@ int lua_totalmemory(lua_State* L) int lua_hostname(lua_State* L) { - size_t sz = 255; - std::string hostname; - hostname.reserve(sz); - - int res = uv_os_gethostname(hostname.data(), &sz); - if (res == UV_ENOBUFS) - { - hostname.reserve(sz); // libuv updates the size to what's required - res = uv_os_gethostname(hostname.data(), &sz); - } - - if (res != 0) - { - luaL_error(L, "libuv error: %s", uv_strerror(res)); - } - - lua_pushlstring(L, hostname.c_str(), hostname.size()); + uvutils::StringResult result = uvutils::getStringFromUv(uv_os_gethostname); + if (result.status < 0) + luaL_error(L, "libuv error: %s", uv_strerror(result.status)); + lua_pushlstring(L, result.value.c_str(), result.value.size()); return 1; } @@ -126,26 +116,12 @@ int lua_uptime(lua_State* L) int lua_tmpdir(lua_State* L) { - size_t size = 255; - std::string tmpdir; - tmpdir.reserve(size); - - int res = uv_os_tmpdir(tmpdir.data(), &size); - if (res == UV_ENOBUFS) - { - tmpdir.reserve(size); // libuv updates the size to what's required - res = uv_os_tmpdir(tmpdir.data(), &size); - } - - if (res != 0) - { - luaL_error(L, "libuv error: %s", uv_strerror(res)); - } - - lua_pushlstring(L, tmpdir.c_str(), tmpdir.size()); + uvutils::StringResult result = uvutils::getStringFromUv(uv_os_tmpdir); + if (result.status < 0) + luaL_error(L, "libuv error: %s", uv_strerror(result.status)); + lua_pushlstring(L, result.value.c_str(), result.value.size()); return 1; - } } // namespace libsystem From d194bfe771235debf6cb661171c6986dc89c6713 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 13:50:43 -0700 Subject: [PATCH 07/15] more debug info --- tools/luthier.luau | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/luthier.luau b/tools/luthier.luau index 81e780641..3c922fb1d 100644 --- a/tools/luthier.luau +++ b/tools/luthier.luau @@ -108,6 +108,7 @@ end local function getSourceRoot() local cwd = process.cwd() + print("Current working directory: " .. cwd) while true do if safeFsType(cwd .. pathSep .. ".LUTE_SENTINEL") == "file" then From ac03a644723c095e1bf3ff6aaa7e797c9abc2c81 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 21:31:56 -0700 Subject: [PATCH 08/15] Remove docs debug prints --- docs/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/package.json b/docs/package.json index 560e18c9b..03fe8a475 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,6 +1,6 @@ { "scripts": { - "gen": "echo $PWD; echo $GITHUB_WORKSPACE; lute run scripts/reference.luau", + "gen": "lute run scripts/reference.luau", "dev": "npm run gen && vitepress dev", "build": "npm run gen && vitepress build", "preview": "vitepress preview" From 2daf05b6becf4d33cccf8ea876183230545dc3d8 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 21:34:57 -0700 Subject: [PATCH 09/15] Remove all temp debug additions --- .github/workflows/docs.yml | 2 -- tools/luthier.luau | 1 - 2 files changed, 3 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index be754592b..ffda5489c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,8 +4,6 @@ on: push: branches: - primary - pull_request: - branches: ["primary"] jobs: build: diff --git a/tools/luthier.luau b/tools/luthier.luau index 3c922fb1d..81e780641 100644 --- a/tools/luthier.luau +++ b/tools/luthier.luau @@ -108,7 +108,6 @@ end local function getSourceRoot() local cwd = process.cwd() - print("Current working directory: " .. cwd) while true do if safeFsType(cwd .. pathSep .. ".LUTE_SENTINEL") == "file" then From e5b37c4b4c18d32ad83ebaed7c60d4950cc237e2 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Fri, 24 Oct 2025 21:49:31 -0700 Subject: [PATCH 10/15] Fix test logic --- tests/path.posix.test.luau | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/path.posix.test.luau b/tests/path.posix.test.luau index edf073508..269b721d7 100644 --- a/tests/path.posix.test.luau +++ b/tests/path.posix.test.luau @@ -483,7 +483,7 @@ test.suite("PathPosixResolveSuite", function(suite) -- This test assumes we're in some working directory local result = path.posix.resolve("documents/file.txt") -- Absolute Windows paths will be parsed as relative posix paths because they don't start with / - assert.eq(result.absolute, system.win32) + assert.neq(result.absolute, system.win32) -- The exact parts will depend on the current working directory -- But we can check that it ends with our relative path local endIndex = #result.parts @@ -513,7 +513,7 @@ test.suite("PathPosixResolveSuite", function(suite) -- Should return normalized current working directory local result = path.posix.resolve() -- Absolute Windows paths will be parsed as relative posix paths because they don't start with / - assert.eq(result.absolute, system.win32) + assert.neq(result.absolute, system.win32) -- Can't test exact parts since cwd varies end) From 5eb5959b4e9c4ed36c542393db47cdef734293f0 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Mon, 27 Oct 2025 09:38:20 -0700 Subject: [PATCH 11/15] Try forcing bash shell to make Windows work --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0b1c8a19..5e80114cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,7 @@ jobs: run: rm .luaurc - name: Run Luau Tests + shell: bash run: find tests -name "*.test.luau" | xargs -I {} ${{ steps.build_lute.outputs.exe_path }} run {} run-lute-cxx-unittests: From 3fef90009f09e70d0828ea936633c32aba10beee Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Mon, 27 Oct 2025 09:52:30 -0700 Subject: [PATCH 12/15] Replace backslashes with forward slashes in bash --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5e80114cc..31a1de384 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - name: Run Luau Tests shell: bash - run: find tests -name "*.test.luau" | xargs -I {} ${{ steps.build_lute.outputs.exe_path }} run {} + run: find tests -name "*.test.luau" | xargs -I {} $(echo '${{ steps.build_lute.outputs.exe_path }}' | tr '\\' '/') run {} run-lute-cxx-unittests: runs-on: ${{ matrix.os }} From d83cc9cfdb03384f363285e407aec9e333033aac Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:14:09 -0700 Subject: [PATCH 13/15] (Revert) undo attempts to fix Windows --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31a1de384..d0b1c8a19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,8 +43,7 @@ jobs: run: rm .luaurc - name: Run Luau Tests - shell: bash - run: find tests -name "*.test.luau" | xargs -I {} $(echo '${{ steps.build_lute.outputs.exe_path }}' | tr '\\' '/') run {} + run: find tests -name "*.test.luau" | xargs -I {} ${{ steps.build_lute.outputs.exe_path }} run {} run-lute-cxx-unittests: runs-on: ${{ matrix.os }} From ddf1b33833b2f5a6dc6fe894719c070aae90cc07 Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:28:16 -0700 Subject: [PATCH 14/15] Use Luau::Variant --- lute/process/src/process.cpp | 18 ++++++++++-------- lute/runtime/include/lute/uvutils.h | 12 ++++++++---- lute/runtime/src/uvutils.cpp | 16 +++++++++++++--- lute/system/src/system.cpp | 18 ++++++++++-------- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/lute/process/src/process.cpp b/lute/process/src/process.cpp index 395cdeaa3..641fa0d33 100644 --- a/lute/process/src/process.cpp +++ b/lute/process/src/process.cpp @@ -433,11 +433,12 @@ int run(lua_State* L) int homedir(lua_State* L) { - uvutils::StringResult result = uvutils::getStringFromUv(uv_os_homedir); - if (result.status < 0) - luaL_error(L, "failed to get home directory: %s", uv_strerror(result.status)); + Luau::Variant result = uvutils::getStringFromUv(uv_os_homedir); + if (uvutils::UvError* error = result.get_if()) + luaL_error(L, "failed to get home directory: %s", error->toString().c_str()); - lua_pushlstring(L, result.value.c_str(), result.value.size()); + std::string* homeDir = result.get_if(); + lua_pushlstring(L, homeDir->c_str(), homeDir->size()); return 1; } @@ -454,11 +455,12 @@ int exitFunc(lua_State* L) int cwd(lua_State* L) { - uvutils::StringResult result = uvutils::getStringFromUv(uv_cwd); - if (result.status < 0) - luaL_error(L, "failed to get current working directory: %s", uv_strerror(result.status)); + Luau::Variant result = uvutils::getStringFromUv(uv_cwd); + if (uvutils::UvError* error = result.get_if()) + luaL_error(L, "failed to get current working directory: %s", error->toString().c_str()); - lua_pushlstring(L, result.value.c_str(), result.value.size()); + std::string* cwd = result.get_if(); + lua_pushlstring(L, cwd->c_str(), cwd->size()); return 1; }; diff --git a/lute/runtime/include/lute/uvutils.h b/lute/runtime/include/lute/uvutils.h index 20c0a2169..32f81455f 100644 --- a/lute/runtime/include/lute/uvutils.h +++ b/lute/runtime/include/lute/uvutils.h @@ -1,20 +1,24 @@ #pragma once +#include "Luau/Variant.h" + #include #include namespace uvutils { -struct StringResult +struct UvError { - int status = 0; - std::string value; + UvError(int code); + std::string toString() const; + + int code; }; typedef int (*BufferWriter)(char* buffer, size_t* size); // Abstracts away buffer management when getting strings from libuv functions. -StringResult getStringFromUv(BufferWriter bufferWriter, size_t initialBufferSize = 256); +Luau::Variant getStringFromUv(BufferWriter bufferWriter, size_t initialBufferSize = 256); } // namespace uvutils diff --git a/lute/runtime/src/uvutils.cpp b/lute/runtime/src/uvutils.cpp index 295e7ceea..eebd00b7c 100644 --- a/lute/runtime/src/uvutils.cpp +++ b/lute/runtime/src/uvutils.cpp @@ -5,7 +5,17 @@ namespace uvutils { -StringResult getStringFromUv(BufferWriter bufferWriter, size_t initialBufferSize) +UvError::UvError(int code) + : code(code) +{ +} + +std::string UvError::toString() const +{ + return uv_strerror(code); +} + +Luau::Variant getStringFromUv(BufferWriter bufferWriter, size_t initialBufferSize) { std::string buffer; size_t size = initialBufferSize; @@ -20,10 +30,10 @@ StringResult getStringFromUv(BufferWriter bufferWriter, size_t initialBufferSize } if (writeStatus < 0) - return StringResult{writeStatus, ""}; + return UvError{writeStatus}; buffer.resize(size); - return StringResult{writeStatus, std::move(buffer)}; + return buffer; } } // namespace uvutils diff --git a/lute/system/src/system.cpp b/lute/system/src/system.cpp index 23e279b32..985ad7392 100644 --- a/lute/system/src/system.cpp +++ b/lute/system/src/system.cpp @@ -91,11 +91,12 @@ int lua_totalmemory(lua_State* L) int lua_hostname(lua_State* L) { - uvutils::StringResult result = uvutils::getStringFromUv(uv_os_gethostname); - if (result.status < 0) - luaL_error(L, "libuv error: %s", uv_strerror(result.status)); + Luau::Variant result = uvutils::getStringFromUv(uv_os_gethostname); + if (uvutils::UvError* error = result.get_if()) + luaL_error(L, "failed to get hostname: %s", error->toString().c_str()); - lua_pushlstring(L, result.value.c_str(), result.value.size()); + std::string* hostname = result.get_if(); + lua_pushlstring(L, hostname->c_str(), hostname->size()); return 1; } @@ -116,11 +117,12 @@ int lua_uptime(lua_State* L) int lua_tmpdir(lua_State* L) { - uvutils::StringResult result = uvutils::getStringFromUv(uv_os_tmpdir); - if (result.status < 0) - luaL_error(L, "libuv error: %s", uv_strerror(result.status)); + Luau::Variant result = uvutils::getStringFromUv(uv_os_tmpdir); + if (uvutils::UvError* error = result.get_if()) + luaL_error(L, "failed to get temporary directory: %s", error->toString().c_str()); - lua_pushlstring(L, result.value.c_str(), result.value.size()); + std::string* tmpDir = result.get_if(); + lua_pushlstring(L, tmpDir->c_str(), tmpDir->size()); return 1; } } // namespace libsystem From a73d1ad6139af32b9b4165a388088035271cf63a Mon Sep 17 00:00:00 2001 From: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Date: Mon, 27 Oct 2025 11:51:34 -0700 Subject: [PATCH 15/15] Use auto for readability --- lute/process/src/process.cpp | 4 ++-- lute/system/src/system.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lute/process/src/process.cpp b/lute/process/src/process.cpp index 641fa0d33..4a4d49c22 100644 --- a/lute/process/src/process.cpp +++ b/lute/process/src/process.cpp @@ -433,7 +433,7 @@ int run(lua_State* L) int homedir(lua_State* L) { - Luau::Variant result = uvutils::getStringFromUv(uv_os_homedir); + auto result = uvutils::getStringFromUv(uv_os_homedir); if (uvutils::UvError* error = result.get_if()) luaL_error(L, "failed to get home directory: %s", error->toString().c_str()); @@ -455,7 +455,7 @@ int exitFunc(lua_State* L) int cwd(lua_State* L) { - Luau::Variant result = uvutils::getStringFromUv(uv_cwd); + auto result = uvutils::getStringFromUv(uv_cwd); if (uvutils::UvError* error = result.get_if()) luaL_error(L, "failed to get current working directory: %s", error->toString().c_str()); diff --git a/lute/system/src/system.cpp b/lute/system/src/system.cpp index 985ad7392..399ddb468 100644 --- a/lute/system/src/system.cpp +++ b/lute/system/src/system.cpp @@ -91,7 +91,7 @@ int lua_totalmemory(lua_State* L) int lua_hostname(lua_State* L) { - Luau::Variant result = uvutils::getStringFromUv(uv_os_gethostname); + auto result = uvutils::getStringFromUv(uv_os_gethostname); if (uvutils::UvError* error = result.get_if()) luaL_error(L, "failed to get hostname: %s", error->toString().c_str()); @@ -117,7 +117,7 @@ int lua_uptime(lua_State* L) int lua_tmpdir(lua_State* L) { - Luau::Variant result = uvutils::getStringFromUv(uv_os_tmpdir); + auto result = uvutils::getStringFromUv(uv_os_tmpdir); if (uvutils::UvError* error = result.get_if()) luaL_error(L, "failed to get temporary directory: %s", error->toString().c_str());