diff --git a/.github/workflows/luac.yml b/.github/workflows/luac.yml new file mode 100644 index 00000000000..405b93356dd --- /dev/null +++ b/.github/workflows/luac.yml @@ -0,0 +1,65 @@ +name: Lua compiler +on: + push: + branches: + - 'main' + - '[0-9]+.[0-9]+' + paths: + - 'radio/src/thirdparty/Lua/**' + - '.github/workflows/luac.yml' + pull_request: + paths: + - 'radio/src/thirdparty/Lua/**' + - '.github/workflows/luac.yml' + workflow_dispatch: + +jobs: + build: + name: Build edgetx-luac (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + steps: + - name: Check out the repo + uses: actions/checkout@v7 + + - name: Build + run: | + cmake -S radio/src/thirdparty/Lua -B build-luac -DCMAKE_BUILD_TYPE=Release + cmake --build build-luac --config Release + + - name: Compile a script and check the bytecode header + run: | + LUAC=$(find build-luac -type f \( -name edgetx-luac -o -name edgetx-luac.exe \) | head -1) + cat > ok.lua <<'EOF' + local t = { 1, 2, 3 } + return { run = function() return #t + 0.5 end } + EOF + "$LUAC" -s -o ok.luac ok.lua + + # signature, version 5.3, format, LUAC_DATA, then sizeof(int), + # sizeof(size_t) (written as int for the radio), Instruction, + # lua_Integer and lua_Number must all be 4 bytes + expected=1b4c7561530019930d0a1a0a0404040404 + actual=$(od -An -tx1 -N17 ok.luac | tr -d ' \n') + if [ "$actual" != "$expected" ]; then + echo "::error::Unexpected bytecode header: $actual (expected $expected)" + exit 1 + fi + + # load the bytecode back through lundump + "$LUAC" -l -p ok.luac > /dev/null + + - name: Reject a script with a syntax error + run: | + LUAC=$(find build-luac -type f \( -name edgetx-luac -o -name edgetx-luac.exe \) | head -1) + printf 'local x =\n' > bad.lua + if "$LUAC" -p bad.lua; then + echo "::error::edgetx-luac accepted a script with a syntax error" + exit 1 + fi diff --git a/radio/src/thirdparty/Lua/src/lobject.h b/radio/src/thirdparty/Lua/src/lobject.h index e55e1568350..19942e09d7d 100644 --- a/radio/src/thirdparty/Lua/src/lobject.h +++ b/radio/src/thirdparty/Lua/src/lobject.h @@ -501,7 +501,7 @@ typedef union Closure { */ #define CommonTable CommonHeader; \ - lu_byte flags; lu_byte lsizenode; struct Table *metatable; + lu_byte flags; lu_byte lsizenode; struct Table *metatable /* ** Tables */ diff --git a/radio/src/thirdparty/Lua/src/luac.c b/radio/src/thirdparty/Lua/src/luac.c index 388e9677290..50cbc7ba4ae 100644 --- a/radio/src/thirdparty/Lua/src/luac.c +++ b/radio/src/thirdparty/Lua/src/luac.c @@ -11,6 +11,11 @@ #if defined(__GNUC__) || defined(__clang__) #include +#elif defined(_MSC_VER) +#include +#if !defined(alloca) +#define alloca _alloca +#endif #endif #include #include