├── .github └── workflows │ ├── build-emscripten-cxx.yml │ ├── build-emscripten.yml │ ├── build-linux-cxx.yml │ ├── build-linux.yml │ ├── build-osx-cxx.yml │ ├── build-osx.yml │ ├── build-windows-cxx.yml │ └── build-windows.yml ├── .gitignore ├── CMakeLists.txt ├── README.md ├── lua-5.4.7-tests ├── all.lua ├── api.lua ├── attrib.lua ├── big.lua ├── bitwise.lua ├── bwcoercion.lua ├── calls.lua ├── closure.lua ├── code.lua ├── constructs.lua ├── coroutine.lua ├── cstack.lua ├── db.lua ├── errors.lua ├── events.lua ├── files.lua ├── gc.lua ├── gengc.lua ├── goto.lua ├── heavy.lua ├── libs │ ├── lib1.c │ ├── lib11.c │ ├── lib2.c │ ├── lib21.c │ ├── lib22.c │ └── makefile ├── literals.lua ├── locals.lua ├── ltests │ ├── ltests.c │ └── ltests.h ├── main.lua ├── math.lua ├── nextvar.lua ├── pm.lua ├── sort.lua ├── strings.lua ├── tpack.lua ├── tracegc.lua ├── utf8.lua ├── vararg.lua └── verybig.lua ├── lua-5.4.7 ├── CMakeLists.txt ├── LuaConfig.cmake.in ├── Makefile ├── README ├── doc │ ├── OSIApproved_100X125.png │ ├── contents.html │ ├── index.css │ ├── logo.gif │ ├── lua.1 │ ├── lua.css │ ├── luac.1 │ ├── manual.css │ ├── manual.html │ └── readme.html ├── include │ ├── lauxlib.h │ ├── lua.h │ ├── lua.hpp │ ├── luaconf.h │ └── lualib.h └── src │ ├── Makefile │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lbaselib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── liolib.c │ ├── ljumptab.h │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── lopnames.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── luac.c │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── lua-config-package-tests ├── CMakeLists.txt └── lua-config-package-build-test.c └── orig_sources ├── lua-5.4.6-tests.tar.gz ├── lua-5.4.6.tar.gz ├── lua-5.4.7-tests.tar.gz └── lua-5.4.7.tar.gz /.github/workflows/build-emscripten-cxx.yml: -------------------------------------------------------------------------------- 1 | name: Build Emscripten as C++ 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build-emsdk: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: mymindstorm/setup-emsdk@v7 14 | 15 | - uses: actions/checkout@v2 16 | 17 | - name: Create Build Environment 18 | # Some projects don't allow in-source building, so create a separate build directory 19 | # We'll use this as our working directory for all subsequent commands 20 | run: emcmake cmake -E make_directory ${{github.workspace}}/build 21 | 22 | - name: Configure CMake 23 | # Use a bash shell so we can use the same syntax for environment variable 24 | # access regardless of the host operating system 25 | shell: bash 26 | working-directory: ${{github.workspace}}/build 27 | # Note the current convention is to use the -S and -B options here to specify source 28 | # and build directories, but this is only available with CMake 3.13 and higher. 29 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 30 | run: emcmake cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DLUA_BUILD_AS_CXX=ON 31 | 32 | - name: Build 33 | working-directory: ${{github.workspace}}/build 34 | shell: bash 35 | # Execute the build. You can specify a specific target with "--target " 36 | run: cmake --build . --config $BUILD_TYPE 37 | 38 | - name: Install 39 | working-directory: ${{github.workspace}}/build 40 | shell: bash 41 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 42 | 43 | ## Test of installing as CXX doesn't really make sense 44 | # - name: Configure Test of CMake Package 45 | # working-directory: ${{github.workspace}} 46 | # shell: bash 47 | # run: cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 48 | 49 | # - name: Build Test of CMake Package 50 | # working-directory: ${{github.workspace}} 51 | # shell: bash 52 | # run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.github/workflows/build-emscripten.yml: -------------------------------------------------------------------------------- 1 | name: Build Emscripten 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build-emsdk: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: mymindstorm/setup-emsdk@v7 14 | 15 | - uses: actions/checkout@v2 16 | 17 | - name: Create Build Environment 18 | # Some projects don't allow in-source building, so create a separate build directory 19 | # We'll use this as our working directory for all subsequent commands 20 | run: emcmake cmake -E make_directory ${{github.workspace}}/build 21 | 22 | - name: Configure CMake 23 | # Use a bash shell so we can use the same syntax for environment variable 24 | # access regardless of the host operating system 25 | shell: bash 26 | working-directory: ${{github.workspace}}/build 27 | # Note the current convention is to use the -S and -B options here to specify source 28 | # and build directories, but this is only available with CMake 3.13 and higher. 29 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 30 | run: emcmake cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE 31 | 32 | - name: Build 33 | working-directory: ${{github.workspace}}/build 34 | shell: bash 35 | # Execute the build. You can specify a specific target with "--target " 36 | run: cmake --build . --config $BUILD_TYPE 37 | 38 | - name: Install 39 | working-directory: ${{github.workspace}}/build 40 | shell: bash 41 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 42 | 43 | # - name: Configure Test of CMake Package 44 | # working-directory: ${{github.workspace}} 45 | # shell: bash 46 | # run: emcmake cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 47 | 48 | # - name: Build Test of CMake Package 49 | # working-directory: ${{github.workspace}} 50 | # shell: bash 51 | # run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.github/workflows/build-linux-cxx.yml: -------------------------------------------------------------------------------- 1 | name: Build Linux as C++ 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | # The CMake configure and build commands are platform agnostic and should work equally 12 | # well on Windows or Mac. You can convert this to a matrix build if you need 13 | # cross-platform coverage. 14 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [ubuntu-latest] 19 | runs-on: ${{ matrix.os }} 20 | name: build-${{ matrix.os }} 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Create Build Environment 26 | # Some projects don't allow in-source building, so create a separate build directory 27 | # We'll use this as our working directory for all subsequent commands 28 | run: cmake -E make_directory ${{github.workspace}}/build 29 | 30 | - name: Configure CMake 31 | # Use a bash shell so we can use the same syntax for environment variable 32 | # access regardless of the host operating system 33 | shell: bash 34 | working-directory: ${{github.workspace}}/build 35 | # Note the current convention is to use the -S and -B options here to specify source 36 | # and build directories, but this is only available with CMake 3.13 and higher. 37 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 38 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DLUA_BUILD_AS_CXX=ON 39 | 40 | - name: Build 41 | working-directory: ${{github.workspace}}/build 42 | shell: bash 43 | # Execute the build. You can specify a specific target with "--target " 44 | run: cmake --build . --config $BUILD_TYPE 45 | 46 | - name: Install 47 | working-directory: ${{github.workspace}}/build 48 | shell: bash 49 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 50 | 51 | - name: Test 52 | working-directory: ${{github.workspace}}/build 53 | shell: bash 54 | run: ctest -V 55 | 56 | ## Test of installing as CXX doesn't really make sense 57 | 58 | # - name: Configure Test of CMake Package 59 | # working-directory: ${{github.workspace}} 60 | # shell: bash 61 | # run: cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 62 | 63 | # - name: Build Test of CMake Package 64 | # working-directory: ${{github.workspace}} 65 | # shell: bash 66 | # run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.github/workflows/build-linux.yml: -------------------------------------------------------------------------------- 1 | name: Build Linux 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | # The CMake configure and build commands are platform agnostic and should work equally 12 | # well on Windows or Mac. You can convert this to a matrix build if you need 13 | # cross-platform coverage. 14 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [ubuntu-latest] 19 | runs-on: ${{ matrix.os }} 20 | name: build-${{ matrix.os }} 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Create Build Environment 26 | # Some projects don't allow in-source building, so create a separate build directory 27 | # We'll use this as our working directory for all subsequent commands 28 | run: cmake -E make_directory ${{github.workspace}}/build 29 | 30 | - name: Configure CMake 31 | # Use a bash shell so we can use the same syntax for environment variable 32 | # access regardless of the host operating system 33 | shell: bash 34 | working-directory: ${{github.workspace}}/build 35 | # Note the current convention is to use the -S and -B options here to specify source 36 | # and build directories, but this is only available with CMake 3.13 and higher. 37 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 38 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE 39 | 40 | - name: Build 41 | working-directory: ${{github.workspace}}/build 42 | shell: bash 43 | # Execute the build. You can specify a specific target with "--target " 44 | run: cmake --build . --config $BUILD_TYPE 45 | 46 | - name: Install 47 | working-directory: ${{github.workspace}}/build 48 | shell: bash 49 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 50 | 51 | - name: Test 52 | working-directory: ${{github.workspace}}/build 53 | shell: bash 54 | run: ctest -V 55 | 56 | - name: Configure Test of CMake Package 57 | working-directory: ${{github.workspace}} 58 | shell: bash 59 | run: cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 60 | 61 | - name: Build Test of CMake Package 62 | working-directory: ${{github.workspace}} 63 | shell: bash 64 | run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.github/workflows/build-osx-cxx.yml: -------------------------------------------------------------------------------- 1 | name: Build OSX as C++ 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | # The CMake configure and build commands are platform agnostic and should work equally 12 | # well on Windows or Mac. You can convert this to a matrix build if you need 13 | # cross-platform coverage. 14 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [ macos-latest ] 19 | runs-on: ${{ matrix.os }} 20 | name: build-${{ matrix.os }} 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Create Build Environment 26 | # Some projects don't allow in-source building, so create a separate build directory 27 | # We'll use this as our working directory for all subsequent commands 28 | run: cmake -E make_directory ${{github.workspace}}/build 29 | 30 | - name: Configure CMake 31 | # Use a bash shell so we can use the same syntax for environment variable 32 | # access regardless of the host operating system 33 | shell: bash 34 | working-directory: ${{github.workspace}}/build 35 | # Note the current convention is to use the -S and -B options here to specify source 36 | # and build directories, but this is only available with CMake 3.13 and higher. 37 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 38 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DLUA_BUILD_AS_CXX=ON 39 | 40 | - name: Build 41 | working-directory: ${{github.workspace}}/build 42 | shell: bash 43 | # Execute the build. You can specify a specific target with "--target " 44 | run: cmake --build . --config $BUILD_TYPE 45 | 46 | - name: Install 47 | working-directory: ${{github.workspace}}/build 48 | shell: bash 49 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 50 | 51 | - name: Test 52 | working-directory: ${{github.workspace}}/build 53 | shell: bash 54 | run: ctest -V 55 | 56 | ## Test of installing as CXX doesn't really make sense 57 | # - name: Configure Test of CMake Package 58 | # working-directory: ${{github.workspace}} 59 | # shell: bash 60 | # run: cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 61 | 62 | # - name: Build Test of CMake Package 63 | # working-directory: ${{github.workspace}} 64 | # shell: bash 65 | # run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.github/workflows/build-osx.yml: -------------------------------------------------------------------------------- 1 | name: Build OSX 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | # The CMake configure and build commands are platform agnostic and should work equally 12 | # well on Windows or Mac. You can convert this to a matrix build if you need 13 | # cross-platform coverage. 14 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [ macos-latest ] 19 | runs-on: ${{ matrix.os }} 20 | name: build-${{ matrix.os }} 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Create Build Environment 26 | # Some projects don't allow in-source building, so create a separate build directory 27 | # We'll use this as our working directory for all subsequent commands 28 | run: cmake -E make_directory ${{github.workspace}}/build 29 | 30 | - name: Configure CMake 31 | # Use a bash shell so we can use the same syntax for environment variable 32 | # access regardless of the host operating system 33 | shell: bash 34 | working-directory: ${{github.workspace}}/build 35 | # Note the current convention is to use the -S and -B options here to specify source 36 | # and build directories, but this is only available with CMake 3.13 and higher. 37 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 38 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE 39 | 40 | - name: Build 41 | working-directory: ${{github.workspace}}/build 42 | shell: bash 43 | # Execute the build. You can specify a specific target with "--target " 44 | run: cmake --build . --config $BUILD_TYPE 45 | 46 | - name: Install 47 | working-directory: ${{github.workspace}}/build 48 | shell: bash 49 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 50 | 51 | 52 | - name: Test 53 | working-directory: ${{github.workspace}}/build 54 | shell: bash 55 | run: ctest -V 56 | 57 | - name: Configure Test of CMake Package 58 | working-directory: ${{github.workspace}} 59 | shell: bash 60 | run: cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 61 | 62 | - name: Build Test of CMake Package 63 | working-directory: ${{github.workspace}} 64 | shell: bash 65 | run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.github/workflows/build-windows-cxx.yml: -------------------------------------------------------------------------------- 1 | name: Build Windows as C++ 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | # The CMake configure and build commands are platform agnostic and should work equally 12 | # well on Windows or Mac. You can convert this to a matrix build if you need 13 | # cross-platform coverage. 14 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [windows-latest] 19 | runs-on: ${{ matrix.os }} 20 | name: build-${{ matrix.os }} 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Create Build Environment 26 | # Some projects don't allow in-source building, so create a separate build directory 27 | # We'll use this as our working directory for all subsequent commands 28 | run: cmake -E make_directory ${{github.workspace}}/build 29 | 30 | - name: Configure CMake 31 | # Use a bash shell so we can use the same syntax for environment variable 32 | # access regardless of the host operating system 33 | shell: bash 34 | working-directory: ${{github.workspace}}/build 35 | # Note the current convention is to use the -S and -B options here to specify source 36 | # and build directories, but this is only available with CMake 3.13 and higher. 37 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 38 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DLUA_BUILD_AS_CXX=ON 39 | 40 | - name: Build 41 | working-directory: ${{github.workspace}}/build 42 | shell: bash 43 | # Execute the build. You can specify a specific target with "--target " 44 | run: cmake --build . --config $BUILD_TYPE 45 | 46 | - name: Install 47 | working-directory: ${{github.workspace}}/build 48 | shell: bash 49 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 50 | 51 | - name: Test 52 | working-directory: ${{github.workspace}}/build 53 | shell: bash 54 | run: ctest -V -C $BUILD_TYPE 55 | 56 | ## Test of installing as CXX doesn't really make sense 57 | # - name: Configure Test of CMake Package 58 | # working-directory: ${{github.workspace}} 59 | # shell: bash 60 | # run: cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 61 | 62 | # - name: Build Test of CMake Package 63 | # working-directory: ${{github.workspace}} 64 | # shell: bash 65 | # run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.github/workflows/build-windows.yml: -------------------------------------------------------------------------------- 1 | name: Build Windows 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 7 | BUILD_TYPE: Release 8 | 9 | jobs: 10 | build: 11 | # The CMake configure and build commands are platform agnostic and should work equally 12 | # well on Windows or Mac. You can convert this to a matrix build if you need 13 | # cross-platform coverage. 14 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | os: [windows-latest] 19 | runs-on: ${{ matrix.os }} 20 | name: build-${{ matrix.os }} 21 | 22 | steps: 23 | - uses: actions/checkout@v2 24 | 25 | - name: Create Build Environment 26 | # Some projects don't allow in-source building, so create a separate build directory 27 | # We'll use this as our working directory for all subsequent commands 28 | run: cmake -E make_directory ${{github.workspace}}/build 29 | 30 | - name: Configure CMake 31 | # Use a bash shell so we can use the same syntax for environment variable 32 | # access regardless of the host operating system 33 | shell: bash 34 | working-directory: ${{github.workspace}}/build 35 | # Note the current convention is to use the -S and -B options here to specify source 36 | # and build directories, but this is only available with CMake 3.13 and higher. 37 | # The CMake binaries on the Github Actions machines are (as of this writing) 3.12 38 | run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE 39 | 40 | - name: Build 41 | working-directory: ${{github.workspace}}/build 42 | shell: bash 43 | # Execute the build. You can specify a specific target with "--target " 44 | run: cmake --build . --config $BUILD_TYPE 45 | 46 | - name: Install 47 | working-directory: ${{github.workspace}}/build 48 | shell: bash 49 | run: cmake --install . --prefix $GITHUB_WORKSPACE/sysroot 50 | 51 | - name: Test 52 | working-directory: ${{github.workspace}}/build 53 | shell: bash 54 | run: ctest -V -C $BUILD_TYPE 55 | 56 | - name: Configure Test of CMake Package 57 | working-directory: ${{github.workspace}} 58 | shell: bash 59 | run: cmake -S $GITHUB_WORKSPACE/lua-config-package-tests -B build-pkg-test -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/sysroot 60 | 61 | - name: Build Test of CMake Package 62 | working-directory: ${{github.workspace}} 63 | shell: bash 64 | run: cmake --build build-pkg-test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | *.obj 5 | *.elf 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Libraries 12 | *.lib 13 | *.a 14 | *.la 15 | *.lo 16 | 17 | # Shared objects (inc. Windows DLLs) 18 | *.dll 19 | *.so 20 | *.so.* 21 | *.dylib 22 | 23 | # Executables 24 | *.exe 25 | *.out 26 | *.app 27 | *.i*86 28 | *.x86_64 29 | *.hex 30 | 31 | # Debug files 32 | *.dSYM/ 33 | *.su 34 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1...3.12) 2 | project(lua LANGUAGES C VERSION 5.4.7) 3 | 4 | option(LUA_SUPPORT_DL "Support dynamic loading of compiled modules" OFF) 5 | option(LUA_BUILD_AS_CXX "Build lua as C++" OFF) 6 | option(LUA_ENABLE_SHARED "Build dynamic liblua" ON) 7 | option(LUA_ENABLE_TESTING "Build and run tests" ON) 8 | 9 | enable_language(CXX) 10 | if(LUA_ENABLE_TESTING) 11 | enable_testing() 12 | endif() 13 | 14 | if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME}) 15 | set(TOP_LEVEL TRUE) 16 | else() 17 | set(TOP_LEVEL FALSE) 18 | endif() 19 | 20 | if(TOP_LEVEL) 21 | option(LUA_BUILD_BINARY "Build lua binary" ON) 22 | option(LUA_BUILD_COMPILER "Build luac compiler" ON) 23 | else() 24 | option(LUA_BUILD_BINARY "Build lua binary" OFF) 25 | option(LUA_BUILD_COMPILER "Build luac compiler" ON) 26 | endif() 27 | 28 | add_subdirectory(lua-${PROJECT_VERSION}) 29 | 30 | if(LUA_ENABLE_TESTING) 31 | add_test(NAME lua-testsuite COMMAND lua -e "_U=true" all.lua WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lua-${CMAKE_PROJECT_VERSION}-tests) 32 | endif() 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lua 2 | CMake based build of Lua 5.4.7 3 | | Build as C | Build as C++ | 4 | | --: | --: | 5 | | ![Build Linux](https://github.com/walterschell/Lua/actions/workflows/build-linux.yml/badge.svg?branch=master) | ![Build Linux as C++](https://github.com/walterschell/Lua/actions/workflows/build-linux-cxx.yml/badge.svg?branch=master) | 6 | | ![Build Windows](https://github.com/walterschell/Lua/actions/workflows/build-windows.yml/badge.svg?branch=master) | ![Build Windows as C++](https://github.com/walterschell/Lua/actions/workflows/build-windows-cxx.yml/badge.svg?branch=master) | 7 | | ![Build OSX](https://github.com/walterschell/Lua/actions/workflows/build-osx.yml/badge.svg?branch=master) | ![Build OSX as C++](https://github.com/walterschell/Lua/actions/workflows/build-osx-cxx.yml/badge.svg?branch=master) | 8 | | ![Build Emscripten](https://github.com/walterschell/Lua/actions/workflows/build-emscripten.yml/badge.svg?branch=master) | ![Build Emscripten as C++](https://github.com/walterschell/Lua/actions/workflows/build-emscripten-cxx.yml/badge.svg?branch=master) | 9 | # Usage 10 | Inside of your project's CMakeLists.txt 11 | ```cmake 12 | add_subdirectory(lua) 13 | ... 14 | target_link_libraries( lua_static) 15 | ``` 16 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/big.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/big.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | if _soft then 5 | return 'a' 6 | end 7 | 8 | print "testing large tables" 9 | 10 | local debug = require"debug" 11 | 12 | local lim = 2^18 + 1000 13 | local prog = { "local y = {0" } 14 | for i = 1, lim do prog[#prog + 1] = i end 15 | prog[#prog + 1] = "}\n" 16 | prog[#prog + 1] = "X = y\n" 17 | prog[#prog + 1] = ("assert(X[%d] == %d)"):format(lim - 1, lim - 2) 18 | prog[#prog + 1] = "return 0" 19 | prog = table.concat(prog, ";") 20 | 21 | local env = {string = string, assert = assert} 22 | local f = assert(load(prog, nil, nil, env)) 23 | 24 | f() 25 | assert(env.X[lim] == lim - 1 and env.X[lim + 1] == lim) 26 | for k in pairs(env) do env[k] = undef end 27 | 28 | -- yields during accesses larger than K (in RK) 29 | setmetatable(env, { 30 | __index = function (t, n) coroutine.yield('g'); return _G[n] end, 31 | __newindex = function (t, n, v) coroutine.yield('s'); _G[n] = v end, 32 | }) 33 | 34 | X = nil 35 | local co = coroutine.wrap(f) 36 | assert(co() == 's') 37 | assert(co() == 'g') 38 | assert(co() == 'g') 39 | assert(co() == 0) 40 | 41 | assert(X[lim] == lim - 1 and X[lim + 1] == lim) 42 | 43 | -- errors in accesses larger than K (in RK) 44 | getmetatable(env).__index = function () end 45 | getmetatable(env).__newindex = function () end 46 | local e, m = pcall(f) 47 | assert(not e and m:find("global 'X'")) 48 | 49 | -- errors in metamethods 50 | getmetatable(env).__newindex = function () error("hi") end 51 | local e, m = xpcall(f, debug.traceback) 52 | assert(not e and m:find("'newindex'")) 53 | 54 | f, X = nil 55 | 56 | coroutine.yield'b' 57 | 58 | if 2^32 == 0 then -- (small integers) { 59 | 60 | print "testing string length overflow" 61 | 62 | local repstrings = 192 -- number of strings to be concatenated 63 | local ssize = math.ceil(2.0^32 / repstrings) + 1 -- size of each string 64 | 65 | assert(repstrings * ssize > 2.0^32) -- it should be larger than maximum size 66 | 67 | local longs = string.rep("\0", ssize) -- create one long string 68 | 69 | -- create function to concatenate 'repstrings' copies of its argument 70 | local rep = assert(load( 71 | "local a = ...; return " .. string.rep("a", repstrings, ".."))) 72 | 73 | local a, b = pcall(rep, longs) -- call that function 74 | 75 | -- it should fail without creating string (result would be too large) 76 | assert(not a and string.find(b, "overflow")) 77 | 78 | end -- } 79 | 80 | print'OK' 81 | 82 | return 'a' 83 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/bwcoercion.lua: -------------------------------------------------------------------------------- 1 | local tonumber, tointeger = tonumber, math.tointeger 2 | local type, getmetatable, rawget, error = type, getmetatable, rawget, error 3 | local strsub = string.sub 4 | 5 | local print = print 6 | 7 | _ENV = nil 8 | 9 | -- Try to convert a value to an integer, without assuming any coercion. 10 | local function toint (x) 11 | x = tonumber(x) -- handle numerical strings 12 | if not x then 13 | return false -- not coercible to a number 14 | end 15 | return tointeger(x) 16 | end 17 | 18 | 19 | -- If operation fails, maybe second operand has a metamethod that should 20 | -- have been called if not for this string metamethod, so try to 21 | -- call it. 22 | local function trymt (x, y, mtname) 23 | if type(y) ~= "string" then -- avoid recalling original metamethod 24 | local mt = getmetatable(y) 25 | local mm = mt and rawget(mt, mtname) 26 | if mm then 27 | return mm(x, y) 28 | end 29 | end 30 | -- if any test fails, there is no other metamethod to be called 31 | error("attempt to '" .. strsub(mtname, 3) .. 32 | "' a " .. type(x) .. " with a " .. type(y), 4) 33 | end 34 | 35 | 36 | local function checkargs (x, y, mtname) 37 | local xi = toint(x) 38 | local yi = toint(y) 39 | if xi and yi then 40 | return xi, yi 41 | else 42 | return trymt(x, y, mtname), nil 43 | end 44 | end 45 | 46 | 47 | local smt = getmetatable("") 48 | 49 | smt.__band = function (x, y) 50 | local x, y = checkargs(x, y, "__band") 51 | return y and x & y or x 52 | end 53 | 54 | smt.__bor = function (x, y) 55 | local x, y = checkargs(x, y, "__bor") 56 | return y and x | y or x 57 | end 58 | 59 | smt.__bxor = function (x, y) 60 | local x, y = checkargs(x, y, "__bxor") 61 | return y and x ~ y or x 62 | end 63 | 64 | smt.__shl = function (x, y) 65 | local x, y = checkargs(x, y, "__shl") 66 | return y and x << y or x 67 | end 68 | 69 | smt.__shr = function (x, y) 70 | local x, y = checkargs(x, y, "__shr") 71 | return y and x >> y or x 72 | end 73 | 74 | smt.__bnot = function (x) 75 | local x, y = checkargs(x, x, "__bnot") 76 | return y and ~x or x 77 | end 78 | 79 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/closure.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/closure.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | print "testing closures" 5 | 6 | local A,B = 0,{g=10} 7 | local function f(x) 8 | local a = {} 9 | for i=1,1000 do 10 | local y = 0 11 | do 12 | a[i] = function () B.g = B.g+1; y = y+x; return y+A end 13 | end 14 | end 15 | local dummy = function () return a[A] end 16 | collectgarbage() 17 | A = 1; assert(dummy() == a[1]); A = 0; 18 | assert(a[1]() == x) 19 | assert(a[3]() == x) 20 | collectgarbage() 21 | assert(B.g == 12) 22 | return a 23 | end 24 | 25 | local a = f(10) 26 | -- force a GC in this level 27 | local x = {[1] = {}} -- to detect a GC 28 | setmetatable(x, {__mode = 'kv'}) 29 | while x[1] do -- repeat until GC 30 | local a = A..A..A..A -- create garbage 31 | A = A+1 32 | end 33 | assert(a[1]() == 20+A) 34 | assert(a[1]() == 30+A) 35 | assert(a[2]() == 10+A) 36 | collectgarbage() 37 | assert(a[2]() == 20+A) 38 | assert(a[2]() == 30+A) 39 | assert(a[3]() == 20+A) 40 | assert(a[8]() == 10+A) 41 | assert(getmetatable(x).__mode == 'kv') 42 | assert(B.g == 19) 43 | 44 | 45 | -- testing equality 46 | a = {} 47 | 48 | for i = 1, 5 do a[i] = function (x) return i + a + _ENV end end 49 | assert(a[3] ~= a[4] and a[4] ~= a[5]) 50 | 51 | do 52 | local a = function (x) return math.sin(_ENV[x]) end 53 | local function f() 54 | return a 55 | end 56 | assert(f() == f()) 57 | end 58 | 59 | 60 | -- testing closures with 'for' control variable 61 | a = {} 62 | for i=1,10 do 63 | a[i] = {set = function(x) i=x end, get = function () return i end} 64 | if i == 3 then break end 65 | end 66 | assert(a[4] == undef) 67 | a[1].set(10) 68 | assert(a[2].get() == 2) 69 | a[2].set('a') 70 | assert(a[3].get() == 3) 71 | assert(a[2].get() == 'a') 72 | 73 | a = {} 74 | local t = {"a", "b"} 75 | for i = 1, #t do 76 | local k = t[i] 77 | a[i] = {set = function(x, y) i=x; k=y end, 78 | get = function () return i, k end} 79 | if i == 2 then break end 80 | end 81 | a[1].set(10, 20) 82 | local r,s = a[2].get() 83 | assert(r == 2 and s == 'b') 84 | r,s = a[1].get() 85 | assert(r == 10 and s == 20) 86 | a[2].set('a', 'b') 87 | r,s = a[2].get() 88 | assert(r == "a" and s == "b") 89 | 90 | 91 | -- testing closures with 'for' control variable x break 92 | local f 93 | for i=1,3 do 94 | f = function () return i end 95 | break 96 | end 97 | assert(f() == 1) 98 | 99 | for k = 1, #t do 100 | local v = t[k] 101 | f = function () return k, v end 102 | break 103 | end 104 | assert(({f()})[1] == 1) 105 | assert(({f()})[2] == "a") 106 | 107 | 108 | -- testing closure x break x return x errors 109 | 110 | local b 111 | function f(x) 112 | local first = 1 113 | while 1 do 114 | if x == 3 and not first then return end 115 | local a = 'xuxu' 116 | b = function (op, y) 117 | if op == 'set' then 118 | a = x+y 119 | else 120 | return a 121 | end 122 | end 123 | if x == 1 then do break end 124 | elseif x == 2 then return 125 | else if x ~= 3 then error() end 126 | end 127 | first = nil 128 | end 129 | end 130 | 131 | for i=1,3 do 132 | f(i) 133 | assert(b('get') == 'xuxu') 134 | b('set', 10); assert(b('get') == 10+i) 135 | b = nil 136 | end 137 | 138 | pcall(f, 4); 139 | assert(b('get') == 'xuxu') 140 | b('set', 10); assert(b('get') == 14) 141 | 142 | 143 | local y, w 144 | -- testing multi-level closure 145 | function f(x) 146 | return function (y) 147 | return function (z) return w+x+y+z end 148 | end 149 | end 150 | 151 | y = f(10) 152 | w = 1.345 153 | assert(y(20)(30) == 60+w) 154 | 155 | 156 | -- testing closures x break 157 | do 158 | local X, Y 159 | local a = math.sin(0) 160 | 161 | while a do 162 | local b = 10 163 | X = function () return b end -- closure with upvalue 164 | if a then break end 165 | end 166 | 167 | do 168 | local b = 20 169 | Y = function () return b end -- closure with upvalue 170 | end 171 | 172 | -- upvalues must be different 173 | assert(X() == 10 and Y() == 20) 174 | end 175 | 176 | 177 | -- testing closures x repeat-until 178 | 179 | local a = {} 180 | local i = 1 181 | repeat 182 | local x = i 183 | a[i] = function () i = x+1; return x end 184 | until i > 10 or a[i]() ~= x 185 | assert(i == 11 and a[1]() == 1 and a[3]() == 3 and i == 4) 186 | 187 | 188 | -- testing closures created in 'then' and 'else' parts of 'if's 189 | a = {} 190 | for i = 1, 10 do 191 | if i % 3 == 0 then 192 | local y = 0 193 | a[i] = function (x) local t = y; y = x; return t end 194 | elseif i % 3 == 1 then 195 | goto L1 196 | error'not here' 197 | ::L1:: 198 | local y = 1 199 | a[i] = function (x) local t = y; y = x; return t end 200 | elseif i % 3 == 2 then 201 | local t 202 | goto l4 203 | ::l4a:: a[i] = t; goto l4b 204 | error("should never be here!") 205 | ::l4:: 206 | local y = 2 207 | t = function (x) local t = y; y = x; return t end 208 | goto l4a 209 | error("should never be here!") 210 | ::l4b:: 211 | end 212 | end 213 | 214 | for i = 1, 10 do 215 | assert(a[i](i * 10) == i % 3 and a[i]() == i * 10) 216 | end 217 | 218 | print'+' 219 | 220 | 221 | -- test for correctly closing upvalues in tail calls of vararg functions 222 | local function t () 223 | local function c(a,b) assert(a=="test" and b=="OK") end 224 | local function v(f, ...) c("test", f() ~= 1 and "FAILED" or "OK") end 225 | local x = 1 226 | return v(function() return x end) 227 | end 228 | t() 229 | 230 | 231 | -- test for debug manipulation of upvalues 232 | local debug = require'debug' 233 | 234 | local foo1, foo2, foo3 235 | do 236 | local a , b, c = 3, 5, 7 237 | foo1 = function () return a+b end; 238 | foo2 = function () return b+a end; 239 | do 240 | local a = 10 241 | foo3 = function () return a+b end; 242 | end 243 | end 244 | 245 | assert(debug.upvalueid(foo1, 1)) 246 | assert(debug.upvalueid(foo1, 2)) 247 | assert(not debug.upvalueid(foo1, 3)) 248 | assert(debug.upvalueid(foo1, 1) == debug.upvalueid(foo2, 2)) 249 | assert(debug.upvalueid(foo1, 2) == debug.upvalueid(foo2, 1)) 250 | assert(debug.upvalueid(foo3, 1)) 251 | assert(debug.upvalueid(foo1, 1) ~= debug.upvalueid(foo3, 1)) 252 | assert(debug.upvalueid(foo1, 2) == debug.upvalueid(foo3, 2)) 253 | 254 | assert(debug.upvalueid(string.gmatch("x", "x"), 1) ~= nil) 255 | 256 | assert(foo1() == 3 + 5 and foo2() == 5 + 3) 257 | debug.upvaluejoin(foo1, 2, foo2, 2) 258 | assert(foo1() == 3 + 3 and foo2() == 5 + 3) 259 | assert(foo3() == 10 + 5) 260 | debug.upvaluejoin(foo3, 2, foo2, 1) 261 | assert(foo3() == 10 + 5) 262 | debug.upvaluejoin(foo3, 2, foo2, 2) 263 | assert(foo3() == 10 + 3) 264 | 265 | assert(not pcall(debug.upvaluejoin, foo1, 3, foo2, 1)) 266 | assert(not pcall(debug.upvaluejoin, foo1, 1, foo2, 3)) 267 | assert(not pcall(debug.upvaluejoin, foo1, 0, foo2, 1)) 268 | assert(not pcall(debug.upvaluejoin, print, 1, foo2, 1)) 269 | assert(not pcall(debug.upvaluejoin, {}, 1, foo2, 1)) 270 | assert(not pcall(debug.upvaluejoin, foo1, 1, print, 1)) 271 | 272 | print'OK' 273 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/cstack.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/cstack.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | 5 | local tracegc = require"tracegc" 6 | 7 | print"testing stack overflow detection" 8 | 9 | -- Segmentation faults in these tests probably result from a C-stack 10 | -- overflow. To avoid these errors, you should set a smaller limit for 11 | -- the use of C stack by Lua, by changing the constant 'LUAI_MAXCCALLS'. 12 | -- Alternatively, you can ensure a larger stack for the program. 13 | 14 | 15 | local function checkerror (msg, f, ...) 16 | local s, err = pcall(f, ...) 17 | assert(not s and string.find(err, msg)) 18 | end 19 | 20 | do print("testing stack overflow in message handling") 21 | local count = 0 22 | local function loop (x, y, z) 23 | count = count + 1 24 | return 1 + loop(x, y, z) 25 | end 26 | tracegc.stop() -- __gc should not be called with a full stack 27 | local res, msg = xpcall(loop, loop) 28 | tracegc.start() 29 | assert(msg == "error in error handling") 30 | print("final count: ", count) 31 | end 32 | 33 | 34 | -- bug since 2.5 (C-stack overflow in recursion inside pattern matching) 35 | do print("testing recursion inside pattern matching") 36 | local function f (size) 37 | local s = string.rep("a", size) 38 | local p = string.rep(".?", size) 39 | return string.match(s, p) 40 | end 41 | local m = f(80) 42 | assert(#m == 80) 43 | checkerror("too complex", f, 2000) 44 | end 45 | 46 | 47 | do print("testing stack-overflow in recursive 'gsub'") 48 | local count = 0 49 | local function foo () 50 | count = count + 1 51 | string.gsub("a", ".", foo) 52 | end 53 | checkerror("stack overflow", foo) 54 | print("final count: ", count) 55 | 56 | print("testing stack-overflow in recursive 'gsub' with metatables") 57 | local count = 0 58 | local t = setmetatable({}, {__index = foo}) 59 | foo = function () 60 | count = count + 1 61 | string.gsub("a", ".", t) 62 | end 63 | checkerror("stack overflow", foo) 64 | print("final count: ", count) 65 | end 66 | 67 | 68 | do -- bug in 5.4.0 69 | print("testing limits in coroutines inside deep calls") 70 | local count = 0 71 | local lim = 1000 72 | local function stack (n) 73 | if n > 0 then return stack(n - 1) + 1 74 | else coroutine.wrap(function () 75 | count = count + 1 76 | stack(lim) 77 | end)() 78 | end 79 | end 80 | 81 | local st, msg = xpcall(stack, function () return "ok" end, lim) 82 | assert(not st and msg == "ok") 83 | print("final count: ", count) 84 | end 85 | 86 | 87 | do -- bug since 5.4.0 88 | local count = 0 89 | print("chain of 'coroutine.close'") 90 | -- create N coroutines forming a list so that each one, when closed, 91 | -- closes the previous one. (With a large enough N, previous Lua 92 | -- versions crash in this test.) 93 | local coro = false 94 | for i = 1, 1000 do 95 | local previous = coro 96 | coro = coroutine.create(function() 97 | local cc = setmetatable({}, {__close=function() 98 | count = count + 1 99 | if previous then 100 | assert(coroutine.close(previous)) 101 | end 102 | end}) 103 | coroutine.yield() -- leaves 'cc' pending to be closed 104 | end) 105 | assert(coroutine.resume(coro)) -- start it and run until it yields 106 | end 107 | local st, msg = coroutine.close(coro) 108 | assert(not st and string.find(msg, "C stack overflow")) 109 | print("final count: ", count) 110 | end 111 | 112 | 113 | do 114 | print("nesting of resuming yielded coroutines") 115 | local count = 0 116 | 117 | local function body () 118 | coroutine.yield() 119 | local f = coroutine.wrap(body) 120 | f(); -- start new coroutine (will stop in previous yield) 121 | count = count + 1 122 | f() -- call it recursively 123 | end 124 | 125 | local f = coroutine.wrap(body) 126 | f() 127 | assert(not pcall(f)) 128 | print("final count: ", count) 129 | end 130 | 131 | 132 | do -- bug in 5.4.2 133 | print("nesting coroutines running after recoverable errors") 134 | local count = 0 135 | local function foo() 136 | count = count + 1 137 | pcall(1) -- create an error 138 | -- running now inside 'precover' ("protected recover") 139 | coroutine.wrap(foo)() -- call another coroutine 140 | end 141 | checkerror("C stack overflow", foo) 142 | print("final count: ", count) 143 | end 144 | 145 | 146 | if T then 147 | print("testing stack recovery") 148 | local N = 0 -- trace number of calls 149 | local LIM = -1 -- will store N just before stack overflow 150 | 151 | -- trace stack size; after stack overflow, it should be 152 | -- the maximum allowed stack size. 153 | local stack1 154 | local dummy 155 | 156 | local function err(msg) 157 | assert(string.find(msg, "stack overflow")) 158 | local _, stacknow = T.stacklevel() 159 | assert(stacknow == stack1 + 200) 160 | end 161 | 162 | -- When LIM==-1, the 'if' is not executed, so this function only 163 | -- counts and stores the stack limits up to overflow. Then, LIM 164 | -- becomes N, and then the 'if' code is run when the stack is 165 | -- full. Then, there is a stack overflow inside 'xpcall', after which 166 | -- the stack must have been restored back to its maximum normal size. 167 | local function f() 168 | dummy, stack1 = T.stacklevel() 169 | if N == LIM then 170 | xpcall(f, err) 171 | local _, stacknow = T.stacklevel() 172 | assert(stacknow == stack1) 173 | return 174 | end 175 | N = N + 1 176 | f() 177 | end 178 | 179 | local topB, sizeB -- top and size Before overflow 180 | local topA, sizeA -- top and size After overflow 181 | topB, sizeB = T.stacklevel() 182 | tracegc.stop() -- __gc should not be called with a full stack 183 | xpcall(f, err) 184 | tracegc.start() 185 | topA, sizeA = T.stacklevel() 186 | -- sizes should be comparable 187 | assert(topA == topB and sizeA < sizeB * 2) 188 | print(string.format("maximum stack size: %d", stack1)) 189 | LIM = N -- will stop recursion at maximum level 190 | N = 0 -- to count again 191 | tracegc.stop() -- __gc should not be called with a full stack 192 | f() 193 | tracegc.start() 194 | print"+" 195 | end 196 | 197 | print'OK' 198 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/gengc.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/gengc.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | print('testing generational garbage collection') 5 | 6 | local debug = require"debug" 7 | 8 | assert(collectgarbage("isrunning")) 9 | 10 | collectgarbage() 11 | 12 | local oldmode = collectgarbage("generational") 13 | 14 | 15 | -- ensure that table barrier evolves correctly 16 | do 17 | local U = {} 18 | -- full collection makes 'U' old 19 | collectgarbage() 20 | assert(not T or T.gcage(U) == "old") 21 | 22 | -- U refers to a new table, so it becomes 'touched1' 23 | U[1] = {x = {234}} 24 | assert(not T or (T.gcage(U) == "touched1" and T.gcage(U[1]) == "new")) 25 | 26 | -- both U and the table survive one more collection 27 | collectgarbage("step", 0) 28 | assert(not T or (T.gcage(U) == "touched2" and T.gcage(U[1]) == "survival")) 29 | 30 | -- both U and the table survive yet another collection 31 | -- now everything is old 32 | collectgarbage("step", 0) 33 | assert(not T or (T.gcage(U) == "old" and T.gcage(U[1]) == "old1")) 34 | 35 | -- data was not corrupted 36 | assert(U[1].x[1] == 234) 37 | end 38 | 39 | 40 | do 41 | -- ensure that 'firstold1' is corrected when object is removed from 42 | -- the 'allgc' list 43 | local function foo () end 44 | local old = {10} 45 | collectgarbage() -- make 'old' old 46 | assert(not T or T.gcage(old) == "old") 47 | setmetatable(old, {}) -- new table becomes OLD0 (barrier) 48 | assert(not T or T.gcage(getmetatable(old)) == "old0") 49 | collectgarbage("step", 0) -- new table becomes OLD1 and firstold1 50 | assert(not T or T.gcage(getmetatable(old)) == "old1") 51 | setmetatable(getmetatable(old), {__gc = foo}) -- get it out of allgc list 52 | collectgarbage("step", 0) -- should not seg. fault 53 | end 54 | 55 | 56 | do -- bug in 5.4.0 57 | -- When an object aged OLD1 is finalized, it is moved from the list 58 | -- 'finobj' to the *beginning* of the list 'allgc', but that part of the 59 | -- list was not being visited by 'markold'. 60 | local A = {} 61 | A[1] = false -- old anchor for object 62 | 63 | -- obj finalizer 64 | local function gcf (obj) 65 | A[1] = obj -- anchor object 66 | assert(not T or T.gcage(obj) == "old1") 67 | obj = nil -- remove it from the stack 68 | collectgarbage("step", 0) -- do a young collection 69 | print(getmetatable(A[1]).x) -- metatable was collected 70 | end 71 | 72 | collectgarbage() -- make A old 73 | local obj = {} -- create a new object 74 | collectgarbage("step", 0) -- make it a survival 75 | assert(not T or T.gcage(obj) == "survival") 76 | setmetatable(obj, {__gc = gcf, x = "+"}) -- create its metatable 77 | assert(not T or T.gcage(getmetatable(obj)) == "new") 78 | obj = nil -- clear object 79 | collectgarbage("step", 0) -- will call obj's finalizer 80 | end 81 | 82 | 83 | do -- another bug in 5.4.0 84 | local old = {10} 85 | collectgarbage() -- make 'old' old 86 | local co = coroutine.create( 87 | function () 88 | local x = nil 89 | local f = function () 90 | return x[1] 91 | end 92 | x = coroutine.yield(f) 93 | coroutine.yield() 94 | end 95 | ) 96 | local _, f = coroutine.resume(co) -- create closure over 'x' in coroutine 97 | collectgarbage("step", 0) -- make upvalue a survival 98 | old[1] = {"hello"} -- 'old' go to grayagain as 'touched1' 99 | coroutine.resume(co, {123}) -- its value will be new 100 | co = nil 101 | collectgarbage("step", 0) -- hit the barrier 102 | assert(f() == 123 and old[1][1] == "hello") 103 | collectgarbage("step", 0) -- run the collector once more 104 | -- make sure old[1] was not collected 105 | assert(f() == 123 and old[1][1] == "hello") 106 | end 107 | 108 | 109 | do -- bug introduced in commit 9cf3299fa 110 | local t = setmetatable({}, {__mode = "kv"}) -- all-weak table 111 | collectgarbage() -- full collection 112 | assert(not T or T.gcage(t) == "old") 113 | t[1] = {10} 114 | assert(not T or (T.gcage(t) == "touched1" and T.gccolor(t) == "gray")) 115 | collectgarbage("step", 0) -- minor collection 116 | assert(not T or (T.gcage(t) == "touched2" and T.gccolor(t) == "black")) 117 | collectgarbage("step", 0) -- minor collection 118 | assert(not T or T.gcage(t) == "old") -- t should be black, but it was gray 119 | t[1] = {10} -- no barrier here, so t was still old 120 | collectgarbage("step", 0) -- minor collection 121 | -- t, being old, is ignored by the collection, so it is not cleared 122 | assert(t[1] == nil) -- fails with the bug 123 | end 124 | 125 | 126 | if T == nil then 127 | (Message or print)('\n >>> testC not active: \z 128 | skipping some generational tests <<<\n') 129 | print 'OK' 130 | return 131 | end 132 | 133 | 134 | -- ensure that userdata barrier evolves correctly 135 | do 136 | local U = T.newuserdata(0, 1) 137 | -- full collection makes 'U' old 138 | collectgarbage() 139 | assert(T.gcage(U) == "old") 140 | 141 | -- U refers to a new table, so it becomes 'touched1' 142 | debug.setuservalue(U, {x = {234}}) 143 | assert(T.gcage(U) == "touched1" and 144 | T.gcage(debug.getuservalue(U)) == "new") 145 | 146 | -- both U and the table survive one more collection 147 | collectgarbage("step", 0) 148 | assert(T.gcage(U) == "touched2" and 149 | T.gcage(debug.getuservalue(U)) == "survival") 150 | 151 | -- both U and the table survive yet another collection 152 | -- now everything is old 153 | collectgarbage("step", 0) 154 | assert(T.gcage(U) == "old" and 155 | T.gcage(debug.getuservalue(U)) == "old1") 156 | 157 | -- data was not corrupted 158 | assert(debug.getuservalue(U).x[1] == 234) 159 | end 160 | 161 | -- just to make sure 162 | assert(collectgarbage'isrunning') 163 | 164 | 165 | 166 | -- just to make sure 167 | assert(collectgarbage'isrunning') 168 | 169 | collectgarbage(oldmode) 170 | 171 | print('OK') 172 | 173 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/goto.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/goto.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | collectgarbage() 5 | 6 | local function errmsg (code, m) 7 | local st, msg = load(code) 8 | assert(not st and string.find(msg, m)) 9 | end 10 | 11 | -- cannot see label inside block 12 | errmsg([[ goto l1; do ::l1:: end ]], "label 'l1'") 13 | errmsg([[ do ::l1:: end goto l1; ]], "label 'l1'") 14 | 15 | -- repeated label 16 | errmsg([[ ::l1:: ::l1:: ]], "label 'l1'") 17 | errmsg([[ ::l1:: do ::l1:: end]], "label 'l1'") 18 | 19 | 20 | -- undefined label 21 | errmsg([[ goto l1; local aa ::l1:: ::l2:: print(3) ]], "local 'aa'") 22 | 23 | -- jumping over variable definition 24 | errmsg([[ 25 | do local bb, cc; goto l1; end 26 | local aa 27 | ::l1:: print(3) 28 | ]], "local 'aa'") 29 | 30 | -- jumping into a block 31 | errmsg([[ do ::l1:: end goto l1 ]], "label 'l1'") 32 | errmsg([[ goto l1 do ::l1:: end ]], "label 'l1'") 33 | 34 | -- cannot continue a repeat-until with variables 35 | errmsg([[ 36 | repeat 37 | if x then goto cont end 38 | local xuxu = 10 39 | ::cont:: 40 | until xuxu < x 41 | ]], "local 'xuxu'") 42 | 43 | -- simple gotos 44 | local x 45 | do 46 | local y = 12 47 | goto l1 48 | ::l2:: x = x + 1; goto l3 49 | ::l1:: x = y; goto l2 50 | end 51 | ::l3:: ::l3_1:: assert(x == 13) 52 | 53 | 54 | -- long labels 55 | do 56 | local prog = [[ 57 | do 58 | local a = 1 59 | goto l%sa; a = a + 1 60 | ::l%sa:: a = a + 10 61 | goto l%sb; a = a + 2 62 | ::l%sb:: a = a + 20 63 | return a 64 | end 65 | ]] 66 | local label = string.rep("0123456789", 40) 67 | prog = string.format(prog, label, label, label, label) 68 | assert(assert(load(prog))() == 31) 69 | end 70 | 71 | 72 | -- ok to jump over local dec. to end of block 73 | do 74 | goto l1 75 | local a = 23 76 | x = a 77 | ::l1::; 78 | end 79 | 80 | while true do 81 | goto l4 82 | goto l1 -- ok to jump over local dec. to end of block 83 | goto l1 -- multiple uses of same label 84 | local x = 45 85 | ::l1:: ;;; 86 | end 87 | ::l4:: assert(x == 13) 88 | 89 | if print then 90 | goto l1 -- ok to jump over local dec. to end of block 91 | error("should not be here") 92 | goto l2 -- ok to jump over local dec. to end of block 93 | local x 94 | ::l1:: ; ::l2:: ;; 95 | else end 96 | 97 | -- to repeat a label in a different function is OK 98 | local function foo () 99 | local a = {} 100 | goto l3 101 | ::l1:: a[#a + 1] = 1; goto l2; 102 | ::l2:: a[#a + 1] = 2; goto l5; 103 | ::l3:: 104 | ::l3a:: a[#a + 1] = 3; goto l1; 105 | ::l4:: a[#a + 1] = 4; goto l6; 106 | ::l5:: a[#a + 1] = 5; goto l4; 107 | ::l6:: assert(a[1] == 3 and a[2] == 1 and a[3] == 2 and 108 | a[4] == 5 and a[5] == 4) 109 | if not a[6] then a[6] = true; goto l3a end -- do it twice 110 | end 111 | 112 | ::l6:: foo() 113 | 114 | 115 | do -- bug in 5.2 -> 5.3.2 116 | local x 117 | ::L1:: 118 | local y -- cannot join this SETNIL with previous one 119 | assert(y == nil) 120 | y = true 121 | if x == nil then 122 | x = 1 123 | goto L1 124 | else 125 | x = x + 1 126 | end 127 | assert(x == 2 and y == true) 128 | end 129 | 130 | -- bug in 5.3 131 | do 132 | local first = true 133 | local a = false 134 | if true then 135 | goto LBL 136 | ::loop:: 137 | a = true 138 | ::LBL:: 139 | if first then 140 | first = false 141 | goto loop 142 | end 143 | end 144 | assert(a) 145 | end 146 | 147 | do -- compiling infinite loops 148 | goto escape -- do not run the infinite loops 149 | ::a:: goto a 150 | ::b:: goto c 151 | ::c:: goto b 152 | end 153 | ::escape:: 154 | -------------------------------------------------------------------------------- 155 | -- testing closing of upvalues 156 | 157 | local debug = require 'debug' 158 | 159 | local function foo () 160 | local t = {} 161 | do 162 | local i = 1 163 | local a, b, c, d 164 | t[1] = function () return a, b, c, d end 165 | ::l1:: 166 | local b 167 | do 168 | local c 169 | t[#t + 1] = function () return a, b, c, d end -- t[2], t[4], t[6] 170 | if i > 2 then goto l2 end 171 | do 172 | local d 173 | t[#t + 1] = function () return a, b, c, d end -- t[3], t[5] 174 | i = i + 1 175 | local a 176 | goto l1 177 | end 178 | end 179 | end 180 | ::l2:: return t 181 | end 182 | 183 | local a = foo() 184 | assert(#a == 6) 185 | 186 | -- all functions share same 'a' 187 | for i = 2, 6 do 188 | assert(debug.upvalueid(a[1], 1) == debug.upvalueid(a[i], 1)) 189 | end 190 | 191 | -- 'b' and 'c' are shared among some of them 192 | for i = 2, 6 do 193 | -- only a[1] uses external 'b'/'b' 194 | assert(debug.upvalueid(a[1], 2) ~= debug.upvalueid(a[i], 2)) 195 | assert(debug.upvalueid(a[1], 3) ~= debug.upvalueid(a[i], 3)) 196 | end 197 | 198 | for i = 3, 5, 2 do 199 | -- inner functions share 'b'/'c' with previous ones 200 | assert(debug.upvalueid(a[i], 2) == debug.upvalueid(a[i - 1], 2)) 201 | assert(debug.upvalueid(a[i], 3) == debug.upvalueid(a[i - 1], 3)) 202 | -- but not with next ones 203 | assert(debug.upvalueid(a[i], 2) ~= debug.upvalueid(a[i + 1], 2)) 204 | assert(debug.upvalueid(a[i], 3) ~= debug.upvalueid(a[i + 1], 3)) 205 | end 206 | 207 | -- only external 'd' is shared 208 | for i = 2, 6, 2 do 209 | assert(debug.upvalueid(a[1], 4) == debug.upvalueid(a[i], 4)) 210 | end 211 | 212 | -- internal 'd's are all different 213 | for i = 3, 5, 2 do 214 | for j = 1, 6 do 215 | assert((debug.upvalueid(a[i], 4) == debug.upvalueid(a[j], 4)) 216 | == (i == j)) 217 | end 218 | end 219 | 220 | -------------------------------------------------------------------------------- 221 | -- testing if x goto optimizations 222 | 223 | local function testG (a) 224 | if a == 1 then 225 | goto l1 226 | error("should never be here!") 227 | elseif a == 2 then goto l2 228 | elseif a == 3 then goto l3 229 | elseif a == 4 then 230 | goto l1 -- go to inside the block 231 | error("should never be here!") 232 | ::l1:: a = a + 1 -- must go to 'if' end 233 | else 234 | goto l4 235 | ::l4a:: a = a * 2; goto l4b 236 | error("should never be here!") 237 | ::l4:: goto l4a 238 | error("should never be here!") 239 | ::l4b:: 240 | end 241 | do return a end 242 | ::l2:: do return "2" end 243 | ::l3:: do return "3" end 244 | ::l1:: return "1" 245 | end 246 | 247 | assert(testG(1) == "1") 248 | assert(testG(2) == "2") 249 | assert(testG(3) == "3") 250 | assert(testG(4) == 5) 251 | assert(testG(5) == 10) 252 | 253 | do 254 | -- if x back goto out of scope of upvalue 255 | local X 256 | goto L1 257 | 258 | ::L2:: goto L3 259 | 260 | ::L1:: do 261 | local a = setmetatable({}, {__close = function () X = true end}) 262 | assert(X == nil) 263 | if a then goto L2 end -- jumping back out of scope of 'a' 264 | end 265 | 266 | ::L3:: assert(X == true) -- checks that 'a' was correctly closed 267 | end 268 | -------------------------------------------------------------------------------- 269 | 270 | 271 | print'OK' 272 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/heavy.lua: -------------------------------------------------------------------------------- 1 | -- $Id: heavy.lua,v 1.7 2017/12/29 15:42:15 roberto Exp $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | local function teststring () 5 | print("creating a string too long") 6 | do 7 | local a = "x" 8 | local st, msg = pcall(function () 9 | while true do 10 | a = a .. a.. a.. a.. a.. a.. a.. a.. a.. a 11 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 12 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 13 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 14 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 15 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 16 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 17 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 18 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 19 | .. a .. a.. a.. a.. a.. a.. a.. a.. a.. a 20 | print(string.format("string with %d bytes", #a)) 21 | end 22 | end) 23 | assert(not st and 24 | (string.find(msg, "string length overflow") or 25 | string.find(msg, "not enough memory"))) 26 | print("string length overflow with " .. #a * 100) 27 | end 28 | print('+') 29 | end 30 | 31 | local function loadrep (x, what) 32 | local p = 1<<20 33 | local s = string.rep(x, p) 34 | local count = 0 35 | local function f() 36 | count = count + p 37 | if count % (0x80*p) == 0 then 38 | io.stderr:write("(", count // 2^20, " M)") 39 | end 40 | return s 41 | end 42 | local st, msg = load(f, "=big") 43 | print("\nmemory: ", collectgarbage'count' * 1024) 44 | msg = string.match(msg, "^[^\n]+") -- get only first line 45 | print(string.format("total: 0x%x %s ('%s')", count, what, msg)) 46 | return st, msg 47 | end 48 | 49 | 50 | function controlstruct () 51 | print("control structure too long") 52 | local lim = ((1 << 24) - 2) // 3 53 | local s = string.rep("a = a + 1\n", lim) 54 | s = "while true do " .. s .. "end" 55 | assert(load(s)) 56 | print("ok with " .. lim .. " lines") 57 | lim = lim + 3 58 | s = string.rep("a = a + 1\n", lim) 59 | s = "while true do " .. s .. "end" 60 | local st, msg = load(s) 61 | assert(not st and string.find(msg, "too long")) 62 | print(msg) 63 | end 64 | 65 | 66 | function manylines () 67 | print("loading chunk with too many lines") 68 | local st, msg = loadrep("\n", "lines") 69 | assert(not st and string.find(msg, "too many lines")) 70 | print('+') 71 | end 72 | 73 | 74 | function hugeid () 75 | print("loading chunk with huge identifier") 76 | local st, msg = loadrep("a", "chars") 77 | assert(not st and 78 | (string.find(msg, "lexical element too long") or 79 | string.find(msg, "not enough memory"))) 80 | print('+') 81 | end 82 | 83 | function toomanyinst () 84 | print("loading chunk with too many instructions") 85 | local st, msg = loadrep("a = 10; ", "instructions") 86 | print('+') 87 | end 88 | 89 | 90 | local function loadrepfunc (prefix, f) 91 | local count = -1 92 | local function aux () 93 | count = count + 1 94 | if count == 0 then 95 | return prefix 96 | else 97 | if count % (0x100000) == 0 then 98 | io.stderr:write("(", count // 2^20, " M)") 99 | end 100 | return f(count) 101 | end 102 | end 103 | local st, msg = load(aux, "k") 104 | print("\nmemory: ", collectgarbage'count' * 1024) 105 | msg = string.match(msg, "^[^\n]+") -- get only first line 106 | print("expected error: ", msg) 107 | end 108 | 109 | 110 | function toomanyconst () 111 | print("loading function with too many constants") 112 | loadrepfunc("function foo () return {0,", 113 | function (n) 114 | -- convert 'n' to a string in the format [["...",]], 115 | -- where '...' is a kind of number in base 128 116 | -- (in a range that does not include either the double quote 117 | -- and the escape.) 118 | return string.char(34, 119 | ((n // 128^0) & 127) + 128, 120 | ((n // 128^1) & 127) + 128, 121 | ((n // 128^2) & 127) + 128, 122 | ((n // 128^3) & 127) + 128, 123 | ((n // 128^4) & 127) + 128, 124 | 34, 44) 125 | end) 126 | end 127 | 128 | 129 | function toomanystr () 130 | local a = {} 131 | local st, msg = pcall(function () 132 | for i = 1, math.huge do 133 | if i % (0x100000) == 0 then 134 | io.stderr:write("(", i // 2^20, " M)") 135 | end 136 | a[i] = string.pack("I", i) 137 | end 138 | end) 139 | local size = #a 140 | a = collectgarbage'count' 141 | print("\nmemory:", a * 1024) 142 | print("expected error:", msg) 143 | print("size:", size) 144 | end 145 | 146 | 147 | function toomanyidx () 148 | local a = {} 149 | local st, msg = pcall(function () 150 | for i = 1, math.huge do 151 | if i % (0x100000) == 0 then 152 | io.stderr:write("(", i // 2^20, " M)") 153 | end 154 | a[i] = i 155 | end 156 | end) 157 | print("\nmemory: ", collectgarbage'count' * 1024) 158 | print("expected error: ", msg) 159 | print("size:", #a) 160 | end 161 | 162 | 163 | 164 | -- teststring() 165 | -- controlstruct() 166 | -- manylines() 167 | -- hugeid() 168 | -- toomanyinst() 169 | -- toomanyconst() 170 | -- toomanystr() 171 | toomanyidx() 172 | 173 | print "OK" 174 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/libs/lib1.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | #include "lauxlib.h" 3 | 4 | static int id (lua_State *L) { 5 | return lua_gettop(L); 6 | } 7 | 8 | 9 | static const struct luaL_Reg funcs[] = { 10 | {"id", id}, 11 | {NULL, NULL} 12 | }; 13 | 14 | 15 | /* function used by lib11.c */ 16 | LUAMOD_API int lib1_export (lua_State *L) { 17 | lua_pushstring(L, "exported"); 18 | return 1; 19 | } 20 | 21 | 22 | LUAMOD_API int onefunction (lua_State *L) { 23 | luaL_checkversion(L); 24 | lua_settop(L, 2); 25 | lua_pushvalue(L, 1); 26 | return 2; 27 | } 28 | 29 | 30 | LUAMOD_API int anotherfunc (lua_State *L) { 31 | luaL_checkversion(L); 32 | lua_pushfstring(L, "%d%%%d\n", (int)lua_tointeger(L, 1), 33 | (int)lua_tointeger(L, 2)); 34 | return 1; 35 | } 36 | 37 | 38 | LUAMOD_API int luaopen_lib1_sub (lua_State *L) { 39 | lua_setglobal(L, "y"); /* 2nd arg: extra value (file name) */ 40 | lua_setglobal(L, "x"); /* 1st arg: module name */ 41 | luaL_newlib(L, funcs); 42 | return 1; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/libs/lib11.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | 3 | /* function from lib1.c */ 4 | int lib1_export (lua_State *L); 5 | 6 | LUAMOD_API int luaopen_lib11 (lua_State *L) { 7 | return lib1_export(L); 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/libs/lib2.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | #include "lauxlib.h" 3 | 4 | static int id (lua_State *L) { 5 | return lua_gettop(L); 6 | } 7 | 8 | 9 | static const struct luaL_Reg funcs[] = { 10 | {"id", id}, 11 | {NULL, NULL} 12 | }; 13 | 14 | 15 | LUAMOD_API int luaopen_lib2 (lua_State *L) { 16 | lua_settop(L, 2); 17 | lua_setglobal(L, "y"); /* y gets 2nd parameter */ 18 | lua_setglobal(L, "x"); /* x gets 1st parameter */ 19 | luaL_newlib(L, funcs); 20 | return 1; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/libs/lib21.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | 3 | 4 | int luaopen_lib2 (lua_State *L); 5 | 6 | LUAMOD_API int luaopen_lib21 (lua_State *L) { 7 | return luaopen_lib2(L); 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/libs/lib22.c: -------------------------------------------------------------------------------- 1 | #include "lua.h" 2 | #include "lauxlib.h" 3 | 4 | static int id (lua_State *L) { 5 | lua_pushboolean(L, 1); 6 | lua_insert(L, 1); 7 | return lua_gettop(L); 8 | } 9 | 10 | 11 | static const struct luaL_Reg funcs[] = { 12 | {"id", id}, 13 | {NULL, NULL} 14 | }; 15 | 16 | 17 | LUAMOD_API int luaopen_lib2 (lua_State *L) { 18 | lua_settop(L, 2); 19 | lua_setglobal(L, "y"); /* y gets 2nd parameter */ 20 | lua_setglobal(L, "x"); /* x gets 1st parameter */ 21 | luaL_newlib(L, funcs); 22 | return 1; 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/libs/makefile: -------------------------------------------------------------------------------- 1 | # change this variable to point to the directory with Lua headers 2 | # of the version being tested 3 | LUA_DIR = ../../ 4 | 5 | CC = gcc 6 | 7 | # compilation should generate Dynamic-Link Libraries 8 | CFLAGS = -Wall -std=gnu99 -O2 -I$(LUA_DIR) -fPIC -shared 9 | 10 | # libraries used by the tests 11 | all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so 12 | touch all 13 | 14 | lib1.so: lib1.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/lua.h 15 | $(CC) $(CFLAGS) -o lib1.so lib1.c 16 | 17 | lib11.so: lib11.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/lua.h 18 | $(CC) $(CFLAGS) -o lib11.so lib11.c 19 | 20 | lib2.so: lib2.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/lua.h 21 | $(CC) $(CFLAGS) -o lib2.so lib2.c 22 | 23 | lib21.so: lib21.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/lua.h 24 | $(CC) $(CFLAGS) -o lib21.so lib21.c 25 | 26 | lib2-v2.so: lib21.c $(LUA_DIR)/luaconf.h $(LUA_DIR)/lua.h 27 | $(CC) $(CFLAGS) -o lib2-v2.so lib22.c 28 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/ltests/ltests.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltests.h $ 3 | ** Internal Header for Debugging of the Lua Implementation 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltests_h 8 | #define ltests_h 9 | 10 | 11 | #include 12 | #include 13 | 14 | /* test Lua with compatibility code */ 15 | #define LUA_COMPAT_MATHLIB 16 | #define LUA_COMPAT_LT_LE 17 | 18 | 19 | #define LUA_DEBUG 20 | 21 | 22 | /* turn on assertions */ 23 | #define LUAI_ASSERT 24 | 25 | 26 | /* to avoid warnings, and to make sure value is really unused */ 27 | #define UNUSED(x) (x=0, (void)(x)) 28 | 29 | 30 | /* test for sizes in 'l_sprintf' (make sure whole buffer is available) */ 31 | #undef l_sprintf 32 | #if !defined(LUA_USE_C89) 33 | #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), snprintf(s,sz,f,i)) 34 | #else 35 | #define l_sprintf(s,sz,f,i) (memset(s,0xAB,sz), sprintf(s,f,i)) 36 | #endif 37 | 38 | 39 | /* get a chance to test code without jump tables */ 40 | #define LUA_USE_JUMPTABLE 0 41 | 42 | 43 | /* use 32-bit integers in random generator */ 44 | #define LUA_RAND32 45 | 46 | 47 | /* memory-allocator control variables */ 48 | typedef struct Memcontrol { 49 | int failnext; 50 | unsigned long numblocks; 51 | unsigned long total; 52 | unsigned long maxmem; 53 | unsigned long memlimit; 54 | unsigned long countlimit; 55 | unsigned long objcount[LUA_NUMTYPES]; 56 | } Memcontrol; 57 | 58 | LUA_API Memcontrol l_memcontrol; 59 | 60 | 61 | /* 62 | ** generic variable for debug tricks 63 | */ 64 | extern void *l_Trick; 65 | 66 | 67 | 68 | /* 69 | ** Function to traverse and check all memory used by Lua 70 | */ 71 | LUAI_FUNC int lua_checkmemory (lua_State *L); 72 | 73 | /* 74 | ** Function to print an object GC-friendly 75 | */ 76 | struct GCObject; 77 | LUAI_FUNC void lua_printobj (lua_State *L, struct GCObject *o); 78 | 79 | 80 | /* test for lock/unlock */ 81 | 82 | struct L_EXTRA { int lock; int *plock; }; 83 | #undef LUA_EXTRASPACE 84 | #define LUA_EXTRASPACE sizeof(struct L_EXTRA) 85 | #define getlock(l) cast(struct L_EXTRA*, lua_getextraspace(l)) 86 | #define luai_userstateopen(l) \ 87 | (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock)) 88 | #define luai_userstateclose(l) \ 89 | lua_assert(getlock(l)->lock == 1 && getlock(l)->plock == &(getlock(l)->lock)) 90 | #define luai_userstatethread(l,l1) \ 91 | lua_assert(getlock(l1)->plock == getlock(l)->plock) 92 | #define luai_userstatefree(l,l1) \ 93 | lua_assert(getlock(l)->plock == getlock(l1)->plock) 94 | #define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0) 95 | #define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0) 96 | 97 | 98 | 99 | LUA_API int luaB_opentests (lua_State *L); 100 | 101 | LUA_API void *debug_realloc (void *ud, void *block, 102 | size_t osize, size_t nsize); 103 | 104 | #if defined(lua_c) 105 | #define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol) 106 | #define luaL_openlibs(L) \ 107 | { (luaL_openlibs)(L); \ 108 | luaL_requiref(L, "T", luaB_opentests, 1); \ 109 | lua_pop(L, 1); } 110 | #endif 111 | 112 | 113 | 114 | /* change some sizes to give some bugs a chance */ 115 | 116 | #undef LUAL_BUFFERSIZE 117 | #define LUAL_BUFFERSIZE 23 118 | #define MINSTRTABSIZE 2 119 | #define MAXIWTHABS 3 120 | 121 | #define STRCACHE_N 23 122 | #define STRCACHE_M 5 123 | 124 | #undef LUAI_USER_ALIGNMENT_T 125 | #define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; } 126 | 127 | 128 | /* 129 | ** This one is not compatible with tests for opcode optimizations, 130 | ** as it blocks some optimizations 131 | #define MAXINDEXRK 0 132 | */ 133 | 134 | 135 | /* make stack-overflow tests run faster */ 136 | #undef LUAI_MAXSTACK 137 | #define LUAI_MAXSTACK 50000 138 | 139 | 140 | /* test mode uses more stack space */ 141 | #undef LUAI_MAXCCALLS 142 | #define LUAI_MAXCCALLS 180 143 | 144 | 145 | /* force Lua to use its own implementations */ 146 | #undef lua_strx2number 147 | #undef lua_number2strx 148 | 149 | 150 | #endif 151 | 152 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/strings.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walterschell/Lua/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0/lua-5.4.7-tests/strings.lua -------------------------------------------------------------------------------- /lua-5.4.7-tests/tracegc.lua: -------------------------------------------------------------------------------- 1 | -- track collections 2 | 3 | local M = {} 4 | 5 | -- import list 6 | local setmetatable, stderr, collectgarbage = 7 | setmetatable, io.stderr, collectgarbage 8 | 9 | _ENV = nil 10 | 11 | local active = false 12 | 13 | 14 | -- each time a table is collected, remark it for finalization on next 15 | -- cycle 16 | local mt = {} 17 | function mt.__gc (o) 18 | stderr:write'.' -- mark progress 19 | if active then 20 | setmetatable(o, mt) -- remark object for finalization 21 | end 22 | end 23 | 24 | 25 | function M.start () 26 | if not active then 27 | active = true 28 | setmetatable({}, mt) -- create initial object 29 | end 30 | end 31 | 32 | 33 | function M.stop () 34 | if active then 35 | active = false 36 | collectgarbage() -- call finalizer for the last time 37 | end 38 | end 39 | 40 | return M 41 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/utf8.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/utf8.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | -- UTF-8 file 5 | 6 | print "testing UTF-8 library" 7 | 8 | local utf8 = require'utf8' 9 | 10 | 11 | local function checkerror (msg, f, ...) 12 | local s, err = pcall(f, ...) 13 | assert(not s and string.find(err, msg)) 14 | end 15 | 16 | 17 | local function len (s) 18 | return #string.gsub(s, "[\x80-\xBF]", "") 19 | end 20 | 21 | 22 | local justone = "^" .. utf8.charpattern .. "$" 23 | 24 | -- 't' is the list of codepoints of 's' 25 | local function checksyntax (s, t) 26 | -- creates a string "return '\u{t[1]}...\u{t[n]}'" 27 | local ts = {"return '"} 28 | for i = 1, #t do ts[i + 1] = string.format("\\u{%x}", t[i]) end 29 | ts[#t + 2] = "'" 30 | ts = table.concat(ts) 31 | -- its execution should result in 's' 32 | assert(assert(load(ts))() == s) 33 | end 34 | 35 | assert(not utf8.offset("alo", 5)) 36 | assert(not utf8.offset("alo", -4)) 37 | 38 | -- 'check' makes several tests over the validity of string 's'. 39 | -- 't' is the list of codepoints of 's'. 40 | local function check (s, t, nonstrict) 41 | local l = utf8.len(s, 1, -1, nonstrict) 42 | assert(#t == l and len(s) == l) 43 | assert(utf8.char(table.unpack(t)) == s) -- 't' and 's' are equivalent 44 | 45 | assert(utf8.offset(s, 0) == 1) 46 | 47 | checksyntax(s, t) 48 | 49 | -- creates new table with all codepoints of 's' 50 | local t1 = {utf8.codepoint(s, 1, -1, nonstrict)} 51 | assert(#t == #t1) 52 | for i = 1, #t do assert(t[i] == t1[i]) end -- 't' is equal to 't1' 53 | 54 | for i = 1, l do -- for all codepoints 55 | local pi = utf8.offset(s, i) -- position of i-th char 56 | local pi1 = utf8.offset(s, 2, pi) -- position of next char 57 | assert(string.find(string.sub(s, pi, pi1 - 1), justone)) 58 | assert(utf8.offset(s, -1, pi1) == pi) 59 | assert(utf8.offset(s, i - l - 1) == pi) 60 | assert(pi1 - pi == #utf8.char(utf8.codepoint(s, pi, pi, nonstrict))) 61 | for j = pi, pi1 - 1 do 62 | assert(utf8.offset(s, 0, j) == pi) 63 | end 64 | for j = pi + 1, pi1 - 1 do 65 | assert(not utf8.len(s, j)) 66 | end 67 | assert(utf8.len(s, pi, pi, nonstrict) == 1) 68 | assert(utf8.len(s, pi, pi1 - 1, nonstrict) == 1) 69 | assert(utf8.len(s, pi, -1, nonstrict) == l - i + 1) 70 | assert(utf8.len(s, pi1, -1, nonstrict) == l - i) 71 | assert(utf8.len(s, 1, pi, nonstrict) == i) 72 | end 73 | 74 | local i = 0 75 | for p, c in utf8.codes(s, nonstrict) do 76 | i = i + 1 77 | assert(c == t[i] and p == utf8.offset(s, i)) 78 | assert(utf8.codepoint(s, p, p, nonstrict) == c) 79 | end 80 | assert(i == #t) 81 | 82 | i = 0 83 | for c in string.gmatch(s, utf8.charpattern) do 84 | i = i + 1 85 | assert(c == utf8.char(t[i])) 86 | end 87 | assert(i == #t) 88 | 89 | for i = 1, l do 90 | assert(utf8.offset(s, i) == utf8.offset(s, i - l - 1, #s + 1)) 91 | end 92 | 93 | end 94 | 95 | 96 | do -- error indication in utf8.len 97 | local function check (s, p) 98 | local a, b = utf8.len(s) 99 | assert(not a and b == p) 100 | end 101 | check("abc\xE3def", 4) 102 | check("\xF4\x9F\xBF", 1) 103 | check("\xF4\x9F\xBF\xBF", 1) 104 | -- spurious continuation bytes 105 | check("汉字\x80", #("汉字") + 1) 106 | check("\x80hello", 1) 107 | check("hel\x80lo", 4) 108 | check("汉字\xBF", #("汉字") + 1) 109 | check("\xBFhello", 1) 110 | check("hel\xBFlo", 4) 111 | end 112 | 113 | -- errors in utf8.codes 114 | do 115 | local function errorcodes (s) 116 | checkerror("invalid UTF%-8 code", 117 | function () 118 | for c in utf8.codes(s) do assert(c) end 119 | end) 120 | end 121 | errorcodes("ab\xff") 122 | errorcodes("\u{110000}") 123 | errorcodes("in\x80valid") 124 | errorcodes("\xbfinvalid") 125 | errorcodes("αλφ\xBFα") 126 | 127 | -- calling interation function with invalid arguments 128 | local f = utf8.codes("") 129 | assert(f("", 2) == nil) 130 | assert(f("", -1) == nil) 131 | assert(f("", math.mininteger) == nil) 132 | 133 | end 134 | 135 | -- error in initial position for offset 136 | checkerror("position out of bounds", utf8.offset, "abc", 1, 5) 137 | checkerror("position out of bounds", utf8.offset, "abc", 1, -4) 138 | checkerror("position out of bounds", utf8.offset, "", 1, 2) 139 | checkerror("position out of bounds", utf8.offset, "", 1, -1) 140 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) 141 | checkerror("continuation byte", utf8.offset, "𦧺", 1, 2) 142 | checkerror("continuation byte", utf8.offset, "\x80", 1) 143 | 144 | -- error in indices for len 145 | checkerror("out of bounds", utf8.len, "abc", 0, 2) 146 | checkerror("out of bounds", utf8.len, "abc", 1, 4) 147 | 148 | 149 | local s = "hello World" 150 | local t = {string.byte(s, 1, -1)} 151 | for i = 1, utf8.len(s) do assert(t[i] == string.byte(s, i)) end 152 | check(s, t) 153 | 154 | check("汉字/漢字", {27721, 23383, 47, 28450, 23383,}) 155 | 156 | do 157 | local s = "áéí\128" 158 | local t = {utf8.codepoint(s,1,#s - 1)} 159 | assert(#t == 3 and t[1] == 225 and t[2] == 233 and t[3] == 237) 160 | checkerror("invalid UTF%-8 code", utf8.codepoint, s, 1, #s) 161 | checkerror("out of bounds", utf8.codepoint, s, #s + 1) 162 | t = {utf8.codepoint(s, 4, 3)} 163 | assert(#t == 0) 164 | checkerror("out of bounds", utf8.codepoint, s, -(#s + 1), 1) 165 | checkerror("out of bounds", utf8.codepoint, s, 1, #s + 1) 166 | -- surrogates 167 | assert(utf8.codepoint("\u{D7FF}") == 0xD800 - 1) 168 | assert(utf8.codepoint("\u{E000}") == 0xDFFF + 1) 169 | assert(utf8.codepoint("\u{D800}", 1, 1, true) == 0xD800) 170 | assert(utf8.codepoint("\u{DFFF}", 1, 1, true) == 0xDFFF) 171 | assert(utf8.codepoint("\u{7FFFFFFF}", 1, 1, true) == 0x7FFFFFFF) 172 | end 173 | 174 | assert(utf8.char() == "") 175 | assert(utf8.char(0, 97, 98, 99, 1) == "\0abc\1") 176 | 177 | assert(utf8.codepoint(utf8.char(0x10FFFF)) == 0x10FFFF) 178 | assert(utf8.codepoint(utf8.char(0x7FFFFFFF), 1, 1, true) == (1<<31) - 1) 179 | 180 | checkerror("value out of range", utf8.char, 0x7FFFFFFF + 1) 181 | checkerror("value out of range", utf8.char, -1) 182 | 183 | local function invalid (s) 184 | checkerror("invalid UTF%-8 code", utf8.codepoint, s) 185 | assert(not utf8.len(s)) 186 | end 187 | 188 | -- UTF-8 representation for 0x11ffff (value out of valid range) 189 | invalid("\xF4\x9F\xBF\xBF") 190 | 191 | -- surrogates 192 | invalid("\u{D800}") 193 | invalid("\u{DFFF}") 194 | 195 | -- overlong sequences 196 | invalid("\xC0\x80") -- zero 197 | invalid("\xC1\xBF") -- 0x7F (should be coded in 1 byte) 198 | invalid("\xE0\x9F\xBF") -- 0x7FF (should be coded in 2 bytes) 199 | invalid("\xF0\x8F\xBF\xBF") -- 0xFFFF (should be coded in 3 bytes) 200 | 201 | 202 | -- invalid bytes 203 | invalid("\x80") -- continuation byte 204 | invalid("\xBF") -- continuation byte 205 | invalid("\xFE") -- invalid byte 206 | invalid("\xFF") -- invalid byte 207 | 208 | 209 | -- empty string 210 | check("", {}) 211 | 212 | -- minimum and maximum values for each sequence size 213 | s = "\0 \x7F\z 214 | \xC2\x80 \xDF\xBF\z 215 | \xE0\xA0\x80 \xEF\xBF\xBF\z 216 | \xF0\x90\x80\x80 \xF4\x8F\xBF\xBF" 217 | s = string.gsub(s, " ", "") 218 | check(s, {0,0x7F, 0x80,0x7FF, 0x800,0xFFFF, 0x10000,0x10FFFF}) 219 | 220 | do 221 | -- original UTF-8 values 222 | local s = "\u{4000000}\u{7FFFFFFF}" 223 | assert(#s == 12) 224 | check(s, {0x4000000, 0x7FFFFFFF}, true) 225 | 226 | s = "\u{200000}\u{3FFFFFF}" 227 | assert(#s == 10) 228 | check(s, {0x200000, 0x3FFFFFF}, true) 229 | 230 | s = "\u{10000}\u{1fffff}" 231 | assert(#s == 8) 232 | check(s, {0x10000, 0x1FFFFF}, true) 233 | end 234 | 235 | local x = "日本語a-4\0éó" 236 | check(x, {26085, 26412, 35486, 97, 45, 52, 0, 233, 243}) 237 | 238 | 239 | -- Supplementary Characters 240 | check("𣲷𠜎𠱓𡁻𠵼ab𠺢", 241 | {0x23CB7, 0x2070E, 0x20C53, 0x2107B, 0x20D7C, 0x61, 0x62, 0x20EA2,}) 242 | 243 | check("𨳊𩶘𦧺𨳒𥄫𤓓\xF4\x8F\xBF\xBF", 244 | {0x28CCA, 0x29D98, 0x269FA, 0x28CD2, 0x2512B, 0x244D3, 0x10ffff}) 245 | 246 | 247 | local i = 0 248 | for p, c in string.gmatch(x, "()(" .. utf8.charpattern .. ")") do 249 | i = i + 1 250 | assert(utf8.offset(x, i) == p) 251 | assert(utf8.len(x, p) == utf8.len(x) - i + 1) 252 | assert(utf8.len(c) == 1) 253 | for j = 1, #c - 1 do 254 | assert(utf8.offset(x, 0, p + j - 1) == p) 255 | end 256 | end 257 | 258 | print'ok' 259 | 260 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/vararg.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/vararg.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | print('testing vararg') 5 | 6 | local function f (a, ...) 7 | local x = {n = select('#', ...), ...} 8 | for i = 1, x.n do assert(a[i] == x[i]) end 9 | return x.n 10 | end 11 | 12 | local function c12 (...) 13 | assert(arg == _G.arg) -- no local 'arg' 14 | local x = {...}; x.n = #x 15 | local res = (x.n==2 and x[1] == 1 and x[2] == 2) 16 | if res then res = 55 end 17 | return res, 2 18 | end 19 | 20 | local function vararg (...) return {n = select('#', ...), ...} end 21 | 22 | local call = function (f, args) return f(table.unpack(args, 1, args.n)) end 23 | 24 | assert(f() == 0) 25 | assert(f({1,2,3}, 1, 2, 3) == 3) 26 | assert(f({"alo", nil, 45, f, nil}, "alo", nil, 45, f, nil) == 5) 27 | 28 | assert(vararg().n == 0) 29 | assert(vararg(nil, nil).n == 2) 30 | 31 | assert(c12(1,2)==55) 32 | local a,b = assert(call(c12, {1,2})) 33 | assert(a == 55 and b == 2) 34 | a = call(c12, {1,2;n=2}) 35 | assert(a == 55 and b == 2) 36 | a = call(c12, {1,2;n=1}) 37 | assert(not a) 38 | assert(c12(1,2,3) == false) 39 | local a = vararg(call(next, {_G,nil;n=2})) 40 | local b,c = next(_G) 41 | assert(a[1] == b and a[2] == c and a.n == 2) 42 | a = vararg(call(call, {c12, {1,2}})) 43 | assert(a.n == 2 and a[1] == 55 and a[2] == 2) 44 | a = call(print, {'+'}) 45 | assert(a == nil) 46 | 47 | local t = {1, 10} 48 | function t:f (...) local arg = {...}; return self[...]+#arg end 49 | assert(t:f(1,4) == 3 and t:f(2) == 11) 50 | print('+') 51 | 52 | local lim = 20 53 | local i, a = 1, {} 54 | while i <= lim do a[i] = i+0.3; i=i+1 end 55 | 56 | function f(a, b, c, d, ...) 57 | local more = {...} 58 | assert(a == 1.3 and more[1] == 5.3 and 59 | more[lim-4] == lim+0.3 and not more[lim-3]) 60 | end 61 | 62 | local function g (a,b,c) 63 | assert(a == 1.3 and b == 2.3 and c == 3.3) 64 | end 65 | 66 | call(f, a) 67 | call(g, a) 68 | 69 | a = {} 70 | i = 1 71 | while i <= lim do a[i] = i; i=i+1 end 72 | assert(call(math.max, a) == lim) 73 | 74 | print("+") 75 | 76 | 77 | -- new-style varargs 78 | 79 | local function oneless (a, ...) return ... end 80 | 81 | function f (n, a, ...) 82 | local b 83 | assert(arg == _G.arg) -- no local 'arg' 84 | if n == 0 then 85 | local b, c, d = ... 86 | return a, b, c, d, oneless(oneless(oneless(...))) 87 | else 88 | n, b, a = n-1, ..., a 89 | assert(b == ...) 90 | return f(n, a, ...) 91 | end 92 | end 93 | 94 | a,b,c,d,e = assert(f(10,5,4,3,2,1)) 95 | assert(a==5 and b==4 and c==3 and d==2 and e==1) 96 | 97 | a,b,c,d,e = f(4) 98 | assert(a==nil and b==nil and c==nil and d==nil and e==nil) 99 | 100 | 101 | -- varargs for main chunks 102 | local f = load[[ return {...} ]] 103 | local x = f(2,3) 104 | assert(x[1] == 2 and x[2] == 3 and x[3] == undef) 105 | 106 | 107 | f = load[[ 108 | local x = {...} 109 | for i=1,select('#', ...) do assert(x[i] == select(i, ...)) end 110 | assert(x[select('#', ...)+1] == undef) 111 | return true 112 | ]] 113 | 114 | assert(f("a", "b", nil, {}, assert)) 115 | assert(f()) 116 | 117 | a = {select(3, table.unpack{10,20,30,40})} 118 | assert(#a == 2 and a[1] == 30 and a[2] == 40) 119 | a = {select(1)} 120 | assert(next(a) == nil) 121 | a = {select(-1, 3, 5, 7)} 122 | assert(a[1] == 7 and a[2] == undef) 123 | a = {select(-2, 3, 5, 7)} 124 | assert(a[1] == 5 and a[2] == 7 and a[3] == undef) 125 | pcall(select, 10000) 126 | pcall(select, -10000) 127 | 128 | 129 | -- bug in 5.2.2 130 | 131 | function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, 132 | p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, 133 | p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, 134 | p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, 135 | p41, p42, p43, p44, p45, p46, p48, p49, p50, ...) 136 | local a1,a2,a3,a4,a5,a6,a7 137 | local a8,a9,a10,a11,a12,a13,a14 138 | end 139 | 140 | -- assertion fail here 141 | f() 142 | 143 | -- missing arguments in tail call 144 | do 145 | local function f(a,b,c) return c, b end 146 | local function g() return f(1,2) end 147 | local a, b = g() 148 | assert(a == nil and b == 2) 149 | end 150 | print('OK') 151 | 152 | -------------------------------------------------------------------------------- /lua-5.4.7-tests/verybig.lua: -------------------------------------------------------------------------------- 1 | -- $Id: testes/verybig.lua $ 2 | -- See Copyright Notice in file all.lua 3 | 4 | print "testing RK" 5 | 6 | -- testing opcodes with RK arguments larger than K limit 7 | local function foo () 8 | local dummy = { 9 | -- fill first 256 entries in table of constants 10 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 11 | 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 12 | 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 13 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 14 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 15 | 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 16 | 97, 98, 99, 100, 101, 102, 103, 104, 17 | 105, 106, 107, 108, 109, 110, 111, 112, 18 | 113, 114, 115, 116, 117, 118, 119, 120, 19 | 121, 122, 123, 124, 125, 126, 127, 128, 20 | 129, 130, 131, 132, 133, 134, 135, 136, 21 | 137, 138, 139, 140, 141, 142, 143, 144, 22 | 145, 146, 147, 148, 149, 150, 151, 152, 23 | 153, 154, 155, 156, 157, 158, 159, 160, 24 | 161, 162, 163, 164, 165, 166, 167, 168, 25 | 169, 170, 171, 172, 173, 174, 175, 176, 26 | 177, 178, 179, 180, 181, 182, 183, 184, 27 | 185, 186, 187, 188, 189, 190, 191, 192, 28 | 193, 194, 195, 196, 197, 198, 199, 200, 29 | 201, 202, 203, 204, 205, 206, 207, 208, 30 | 209, 210, 211, 212, 213, 214, 215, 216, 31 | 217, 218, 219, 220, 221, 222, 223, 224, 32 | 225, 226, 227, 228, 229, 230, 231, 232, 33 | 233, 234, 235, 236, 237, 238, 239, 240, 34 | 241, 242, 243, 244, 245, 246, 247, 248, 35 | 249, 250, 251, 252, 253, 254, 255, 256, 36 | } 37 | assert(24.5 + 0.6 == 25.1) 38 | local t = {foo = function (self, x) return x + self.x end, x = 10} 39 | t.t = t 40 | assert(t:foo(1.5) == 11.5) 41 | assert(t.t:foo(0.5) == 10.5) -- bug in 5.2 alpha 42 | assert(24.3 == 24.3) 43 | assert((function () return t.x end)() == 10) 44 | end 45 | 46 | 47 | foo() 48 | foo = nil 49 | 50 | if _soft then return 10 end 51 | 52 | print "testing large programs (>64k)" 53 | 54 | -- template to create a very big test file 55 | local prog = [[$ 56 | 57 | local a,b 58 | 59 | b = {$1$ 60 | b30009 = 65534, 61 | b30010 = 65535, 62 | b30011 = 65536, 63 | b30012 = 65537, 64 | b30013 = 16777214, 65 | b30014 = 16777215, 66 | b30015 = 16777216, 67 | b30016 = 16777217, 68 | b30017 = 0x7fffff, 69 | b30018 = -0x7fffff, 70 | b30019 = 0x1ffffff, 71 | b30020 = -0x1ffffd, 72 | b30021 = -65534, 73 | b30022 = -65535, 74 | b30023 = -65536, 75 | b30024 = -0xffffff, 76 | b30025 = 15012.5, 77 | $2$ 78 | }; 79 | 80 | assert(b.a50008 == 25004 and b["a11"] == -5.5) 81 | assert(b.a33007 == -16503.5 and b.a50009 == -25004.5) 82 | assert(b["b"..30024] == -0xffffff) 83 | 84 | function b:xxx (a,b) return a+b end 85 | assert(b:xxx(10, 12) == 22) -- pushself with non-constant index 86 | b["xxx"] = undef 87 | 88 | local s = 0; local n=0 89 | for a,b in pairs(b) do s=s+b; n=n+1 end 90 | -- with 32-bit floats, exact value of 's' depends on summation order 91 | assert(81800000.0 < s and s < 81860000 and n == 70001) 92 | 93 | a = nil; b = nil 94 | print'+' 95 | 96 | local function f(x) b=x end 97 | 98 | a = f{$3$} or 10 99 | 100 | assert(a==10) 101 | assert(b[1] == "a10" and b[2] == 5 and b[#b-1] == "a50009") 102 | 103 | 104 | function xxxx (x) return b[x] end 105 | 106 | assert(xxxx(3) == "a11") 107 | 108 | a = nil; b=nil 109 | xxxx = nil 110 | 111 | return 10 112 | 113 | ]] 114 | 115 | -- functions to fill in the $n$ 116 | 117 | local function sig (x) 118 | return (x % 2 == 0) and '' or '-' 119 | end 120 | 121 | local F = { 122 | function () -- $1$ 123 | for i=10,50009 do 124 | io.write('a', i, ' = ', sig(i), 5+((i-10)/2), ',\n') 125 | end 126 | end, 127 | 128 | function () -- $2$ 129 | for i=30026,50009 do 130 | io.write('b', i, ' = ', sig(i), 15013+((i-30026)/2), ',\n') 131 | end 132 | end, 133 | 134 | function () -- $3$ 135 | for i=10,50009 do 136 | io.write('"a', i, '", ', sig(i), 5+((i-10)/2), ',\n') 137 | end 138 | end, 139 | } 140 | 141 | local file = os.tmpname() 142 | io.output(file) 143 | for s in string.gmatch(prog, "$([^$]+)") do 144 | local n = tonumber(s) 145 | if not n then io.write(s) else F[n]() end 146 | end 147 | io.close() 148 | local result = dofile(file) 149 | assert(os.remove(file)) 150 | print'OK' 151 | return result 152 | 153 | -------------------------------------------------------------------------------- /lua-5.4.7/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LUA_LIB_SRCS 2 | "src/lapi.c" 3 | "src/lcode.c" 4 | "src/lctype.c" 5 | "src/ldebug.c" 6 | "src/ldo.c" 7 | "src/ldump.c" 8 | "src/lfunc.c" 9 | "src/lgc.c" 10 | "src/llex.c" 11 | "src/lmem.c" 12 | "src/lobject.c" 13 | "src/lopcodes.c" 14 | "src/lparser.c" 15 | "src/lstate.c" 16 | "src/lstring.c" 17 | "src/ltable.c" 18 | "src/ltm.c" 19 | "src/lundump.c" 20 | "src/lvm.c" 21 | "src/lzio.c" 22 | "src/lauxlib.c" 23 | "src/lbaselib.c" 24 | "src/lcorolib.c" 25 | "src/ldblib.c" 26 | "src/liolib.c" 27 | "src/lmathlib.c" 28 | "src/loadlib.c" 29 | "src/loslib.c" 30 | "src/lstrlib.c" 31 | "src/ltablib.c" 32 | "src/lutf8lib.c" 33 | "src/linit.c" 34 | ) 35 | 36 | set(TARGETS_TO_INSTALL lua_internal lua_include) 37 | 38 | set(LUA_LINKED_LIBRARIES) 39 | 40 | if(LUA_BUILD_AS_CXX) 41 | set_source_files_properties(${LUA_LIB_SRCS} "src/lua.c" "src/luac.c" PROPERTIES LANGUAGE CXX ) 42 | endif() 43 | 44 | add_library(lua_internal INTERFACE) 45 | 46 | add_library(lua_include INTERFACE) 47 | 48 | target_include_directories(lua_include INTERFACE 49 | $ 50 | $ 51 | ) 52 | 53 | target_link_libraries(lua_internal INTERFACE lua_include) 54 | 55 | if(LUA_ENABLE_SHARED) 56 | add_library(lua_shared SHARED ${LUA_LIB_SRCS}) 57 | target_link_libraries(lua_shared PRIVATE lua_internal PUBLIC lua_include) 58 | set_target_properties(lua_shared PROPERTIES 59 | VERSION "${PACKAGE_VERSION}" 60 | ) 61 | if(WIN32) 62 | target_compile_definitions(lua_shared PRIVATE LUA_BUILD_AS_DLL) 63 | endif() 64 | list(APPEND TARGETS_TO_INSTALL lua_shared) 65 | if(BUILD_SHARED_LIBS) 66 | add_library(Lua::Library ALIAS lua_shared) 67 | elseif(NOT TOP_LEVEL) 68 | set_target_properties(lua_shared PROPERTIES 69 | EXCLUDE_FROM_ALL ON 70 | ) 71 | endif() 72 | endif() 73 | 74 | add_library(lua_static STATIC ${LUA_LIB_SRCS}) 75 | target_link_libraries(lua_static PRIVATE lua_internal PUBLIC lua_include) 76 | set_target_properties(lua_static PROPERTIES 77 | VERSION "${PACKAGE_VERSION}" 78 | ) 79 | list(APPEND TARGETS_TO_INSTALL lua_static) 80 | if(NOT BUILD_SHARED_LIBS OR NOT LUA_ENABLE_SHARED) 81 | add_library(Lua::Library ALIAS lua_static) 82 | endif() 83 | 84 | 85 | if(UNIX) 86 | if(NOT EMSCRIPTEN) 87 | find_library(LIBM m) 88 | #TODO: Redo this with find_package 89 | if(NOT LIBM) 90 | message(FATAL_ERROR "libm not found and is required by lua") 91 | endif() 92 | target_compile_definitions(lua_internal INTERFACE "LUA_USE_POSIX") 93 | target_link_libraries(lua_internal INTERFACE m) 94 | list(APPEND LUA_LINKED_LIBRARIES m) 95 | if(LUA_SUPPORT_DL) 96 | find_library(LIBDL "${CMAKE_DL_LIBS}") 97 | if(NOT LIBDL) 98 | message(FATAL_ERROR "libdl not found and is required by lua") 99 | endif() 100 | target_compile_definitions(lua_internal INTERFACE "LUA_USE_DLOPEN") 101 | target_link_libraries(lua_internal INTERFACE "${CMAKE_DL_LIBS}") 102 | list(APPEND LUA_LINKED_LIBRARIES "${CMAKE_DL_LIBS}") 103 | endif() 104 | endif() 105 | 106 | target_compile_options(lua_internal 107 | INTERFACE "-Wall" "-Wextra" 108 | ) 109 | elseif(Win32) 110 | target_compile_options(lua_internal 111 | INTERFACE "/Wall" 112 | ) 113 | endif() 114 | 115 | if(LUA_BUILD_BINARY) 116 | include(CheckIncludeFile) 117 | CHECK_INCLUDE_FILE("readline/readline.h" HAVE_READLINE_READLINE_H) 118 | 119 | add_executable(lua "src/lua.c") 120 | # Can not use lua_shared because some symbols are not exported 121 | target_link_libraries(lua PRIVATE lua_static) 122 | set_target_properties(lua PROPERTIES 123 | RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} 124 | ) 125 | if (HAVE_READLINE_READLINE_H) 126 | target_compile_definitions(lua PRIVATE "LUA_USE_READLINE") 127 | target_link_libraries(lua PUBLIC readline) 128 | endif() 129 | list(APPEND TARGETS_TO_INSTALL lua) 130 | endif() 131 | 132 | if(LUA_BUILD_COMPILER) 133 | add_executable(luac "src/luac.c") 134 | target_link_libraries(luac PRIVATE lua_static) 135 | set_target_properties(luac PROPERTIES 136 | RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} 137 | ) 138 | list(APPEND TARGETS_TO_INSTALL luac) 139 | endif() 140 | 141 | install(TARGETS ${TARGETS_TO_INSTALL} 142 | EXPORT LuaTargets 143 | ) 144 | 145 | install(DIRECTORY include/ TYPE INCLUDE) 146 | 147 | include(CMakePackageConfigHelpers) 148 | 149 | get_target_property(LUA_EXPORT_LIBRARY Lua::Library ALIASED_TARGET) 150 | write_basic_package_version_file( 151 | LuaConfigVersion.cmake 152 | VERSION ${PACKAGE_VERSION} 153 | COMPATIBILITY SameMajorVersion 154 | ) 155 | 156 | install(EXPORT LuaTargets 157 | FILE LuaTargets.cmake 158 | DESTINATION "share/cmake/Lua" 159 | NAMESPACE Lua:: 160 | ) 161 | 162 | configure_package_config_file( 163 | LuaConfig.cmake.in 164 | "${CMAKE_CURRENT_BINARY_DIR}/LuaConfig.cmake" 165 | INSTALL_DESTINATION "share/cmake/Lua" 166 | ) 167 | 168 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/LuaConfig.cmake" 169 | "${CMAKE_CURRENT_BINARY_DIR}/LuaConfigVersion.cmake" 170 | DESTINATION "share/cmake/Lua" 171 | ) 172 | -------------------------------------------------------------------------------- /lua-5.4.7/LuaConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/LuaTargets.cmake") 4 | 5 | set_and_check(LUA_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include") 6 | add_library(Lua::Library ALIAS "Lua::@LUA_EXPORT_LIBRARY@") 7 | get_target_property(LUA_CONFIG "Lua::@LUA_EXPORT_LIBRARY@" IMPORTED_CONFIGURATIONS) 8 | get_target_property(LUA_LIBRARY "Lua::@LUA_EXPORT_LIBRARY@" "IMPORTED_LOCATION_${LUA_CONFIG}") 9 | set(LUA_LIBRARIES "${LUA_LIBRARY}") 10 | add_library(LUA_INCLUDE_LIB INTERFACE) 11 | target_include_directories(LUA_INCLUDE_LIB INTERFACE "${LUA_INCLUDE_DIR}") 12 | list(APPEND LUA_LIBRARIES LUA_INCLUDE_LIB) 13 | 14 | foreach(LIB_NAME @LUA_LINKED_LIBRARIES@) 15 | find_library(LIB_LOCATION "${LIB_NAME}") 16 | if(NOT LIB_LOCATION) 17 | message(FATAL_ERROR "lib${LIB_NAME} not found and is required by lua") 18 | else() 19 | list(APPEND LUA_LIBRARIES "${LIB_LOCATION}") 20 | endif() 21 | endforeach() 22 | 23 | check_required_components(Lua) 24 | -------------------------------------------------------------------------------- /lua-5.4.7/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for installing Lua 2 | # See doc/readme.html for installation and customization instructions. 3 | 4 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 5 | 6 | # Your platform. See PLATS for possible values. 7 | PLAT= guess 8 | 9 | # Where to install. The installation starts in the src and doc directories, 10 | # so take care if INSTALL_TOP is not an absolute path. See the local target. 11 | # You may want to make INSTALL_LMOD and INSTALL_CMOD consistent with 12 | # LUA_ROOT, LUA_LDIR, and LUA_CDIR in luaconf.h. 13 | INSTALL_TOP= /usr/local 14 | INSTALL_BIN= $(INSTALL_TOP)/bin 15 | INSTALL_INC= $(INSTALL_TOP)/include 16 | INSTALL_LIB= $(INSTALL_TOP)/lib 17 | INSTALL_MAN= $(INSTALL_TOP)/man/man1 18 | INSTALL_LMOD= $(INSTALL_TOP)/share/lua/$V 19 | INSTALL_CMOD= $(INSTALL_TOP)/lib/lua/$V 20 | 21 | # How to install. If your install program does not support "-p", then 22 | # you may have to run ranlib on the installed liblua.a. 23 | INSTALL= install -p 24 | INSTALL_EXEC= $(INSTALL) -m 0755 25 | INSTALL_DATA= $(INSTALL) -m 0644 26 | # 27 | # If you don't have "install" you can use "cp" instead. 28 | # INSTALL= cp -p 29 | # INSTALL_EXEC= $(INSTALL) 30 | # INSTALL_DATA= $(INSTALL) 31 | 32 | # Other utilities. 33 | MKDIR= mkdir -p 34 | RM= rm -f 35 | 36 | # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= 37 | 38 | # Convenience platforms targets. 39 | PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris 40 | 41 | # What to install. 42 | TO_BIN= lua luac 43 | TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp 44 | TO_LIB= liblua.a 45 | TO_MAN= lua.1 luac.1 46 | 47 | # Lua version and release. 48 | V= 5.4 49 | R= $V.7 50 | 51 | # Targets start here. 52 | all: $(PLAT) 53 | 54 | $(PLATS) help test clean: 55 | @cd src && $(MAKE) $@ 56 | 57 | install: dummy 58 | cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD) 59 | cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN) 60 | cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) 61 | cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) 62 | cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) 63 | 64 | uninstall: 65 | cd src && cd $(INSTALL_BIN) && $(RM) $(TO_BIN) 66 | cd src && cd $(INSTALL_INC) && $(RM) $(TO_INC) 67 | cd src && cd $(INSTALL_LIB) && $(RM) $(TO_LIB) 68 | cd doc && cd $(INSTALL_MAN) && $(RM) $(TO_MAN) 69 | 70 | local: 71 | $(MAKE) install INSTALL_TOP=../install 72 | 73 | # make may get confused with install/ if it does not support .PHONY. 74 | dummy: 75 | 76 | # Echo config parameters. 77 | echo: 78 | @cd src && $(MAKE) -s echo 79 | @echo "PLAT= $(PLAT)" 80 | @echo "V= $V" 81 | @echo "R= $R" 82 | @echo "TO_BIN= $(TO_BIN)" 83 | @echo "TO_INC= $(TO_INC)" 84 | @echo "TO_LIB= $(TO_LIB)" 85 | @echo "TO_MAN= $(TO_MAN)" 86 | @echo "INSTALL_TOP= $(INSTALL_TOP)" 87 | @echo "INSTALL_BIN= $(INSTALL_BIN)" 88 | @echo "INSTALL_INC= $(INSTALL_INC)" 89 | @echo "INSTALL_LIB= $(INSTALL_LIB)" 90 | @echo "INSTALL_MAN= $(INSTALL_MAN)" 91 | @echo "INSTALL_LMOD= $(INSTALL_LMOD)" 92 | @echo "INSTALL_CMOD= $(INSTALL_CMOD)" 93 | @echo "INSTALL_EXEC= $(INSTALL_EXEC)" 94 | @echo "INSTALL_DATA= $(INSTALL_DATA)" 95 | 96 | # Echo pkg-config data. 97 | pc: 98 | @echo "version=$R" 99 | @echo "prefix=$(INSTALL_TOP)" 100 | @echo "libdir=$(INSTALL_LIB)" 101 | @echo "includedir=$(INSTALL_INC)" 102 | 103 | # Targets that do not create files (not all makes understand .PHONY). 104 | .PHONY: all $(PLATS) help test clean install uninstall local dummy echo pc 105 | 106 | # (end of Makefile) 107 | -------------------------------------------------------------------------------- /lua-5.4.7/README: -------------------------------------------------------------------------------- 1 | 2 | This is Lua 5.4.7, released on 13 Jun 2024. 3 | 4 | For installation instructions, license details, and 5 | further information about Lua, see doc/readme.html. 6 | 7 | -------------------------------------------------------------------------------- /lua-5.4.7/doc/OSIApproved_100X125.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walterschell/Lua/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0/lua-5.4.7/doc/OSIApproved_100X125.png -------------------------------------------------------------------------------- /lua-5.4.7/doc/index.css: -------------------------------------------------------------------------------- 1 | ul { 2 | list-style-type: none ; 3 | } 4 | 5 | ul.contents { 6 | padding: 0 ; 7 | } 8 | 9 | table { 10 | border: none ; 11 | border-spacing: 0 ; 12 | border-collapse: collapse ; 13 | } 14 | 15 | td { 16 | vertical-align: top ; 17 | padding: 0 ; 18 | text-align: left ; 19 | line-height: 1.25 ; 20 | width: 15% ; 21 | } 22 | -------------------------------------------------------------------------------- /lua-5.4.7/doc/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walterschell/Lua/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0/lua-5.4.7/doc/logo.gif -------------------------------------------------------------------------------- /lua-5.4.7/doc/lua.1: -------------------------------------------------------------------------------- 1 | .\" $Id: lua.man,v 1.14 2024/05/08 18:48:27 lhf Exp $ 2 | .TH LUA 1 "$Date: 2024/05/08 18:48:27 $" 3 | .SH NAME 4 | lua \- Lua interpreter 5 | .SH SYNOPSIS 6 | .B lua 7 | [ 8 | .I options 9 | ] 10 | [ 11 | .I script 12 | [ 13 | .I args 14 | ] 15 | ] 16 | .SH DESCRIPTION 17 | .B lua 18 | is the standalone Lua interpreter. 19 | It loads and executes Lua programs, 20 | either in textual source form or 21 | in precompiled binary form. 22 | (Precompiled binaries are output by 23 | .BR luac , 24 | the Lua compiler.) 25 | .B lua 26 | can be used as a batch interpreter and also interactively. 27 | .LP 28 | After handling the 29 | .IR options , 30 | the Lua program in file 31 | .I script 32 | is loaded and executed. 33 | The 34 | .I args 35 | are available to 36 | .I script 37 | as strings in a global table named 38 | .B arg 39 | and also as arguments to its main function. 40 | When called without arguments, 41 | .B lua 42 | behaves as 43 | .B "lua \-v \-i" 44 | if the standard input is a terminal, 45 | and as 46 | .B "lua \-" 47 | otherwise. 48 | .LP 49 | In interactive mode, 50 | .B lua 51 | prompts the user, 52 | reads lines from the standard input, 53 | and executes them as they are read. 54 | If the line contains an expression, 55 | then the line is evaluated and the result is printed. 56 | If a line does not contain a complete statement, 57 | then a secondary prompt is displayed and 58 | lines are read until a complete statement is formed or 59 | a syntax error is found. 60 | .LP 61 | Before handling command line options and scripts, 62 | .B lua 63 | checks the contents of the environment variables 64 | .B LUA_INIT_5_4 65 | and 66 | .BR LUA_INIT , 67 | in that order. 68 | If the contents are of the form 69 | .RI '@ filename ', 70 | then 71 | .I filename 72 | is executed. 73 | Otherwise, the contents are assumed to be a Lua statement and is executed. 74 | When 75 | .B LUA_INIT_5_4 76 | is defined, 77 | .B LUA_INIT 78 | is ignored. 79 | .SH OPTIONS 80 | .TP 81 | .BI \-e " stat" 82 | execute statement 83 | .IR stat . 84 | .TP 85 | .B \-i 86 | enter interactive mode after executing 87 | .IR script . 88 | .TP 89 | .BI \-l " mod" 90 | require library 91 | .I mod 92 | into global 93 | .IR mod . 94 | .TP 95 | .BI \-l " g=mod" 96 | require library 97 | .I mod 98 | into global 99 | .IR g . 100 | .TP 101 | .B \-v 102 | show version information. 103 | .TP 104 | .B \-E 105 | ignore environment variables. 106 | .TP 107 | .B \-W 108 | turn warnings on. 109 | .TP 110 | .B \-\- 111 | stop handling options. 112 | .TP 113 | .B \- 114 | stop handling options and execute the standard input as a file. 115 | .SH ENVIRONMENT VARIABLES 116 | The following environment variables affect the execution of 117 | .BR lua . 118 | When defined, 119 | the version-specific variants take priority 120 | and the version-neutral variants are ignored. 121 | .TP 122 | .B LUA_INIT, LUA_INIT_5_4 123 | Code to be executed before command line options and scripts. 124 | .TP 125 | .B LUA_PATH, LUA_PATH_5_4 126 | Initial value of package.path, 127 | the path used by require to search for Lua loaders. 128 | .TP 129 | .B LUA_CPATH, LUA_CPATH_5_4 130 | Initial value of package.cpath, 131 | the path used by require to search for C loaders. 132 | .SH EXIT STATUS 133 | If a script calls os.exit, 134 | then 135 | .B lua 136 | exits with the given exit status. 137 | Otherwise, 138 | .B lua 139 | exits 140 | with EXIT_SUCCESS (0 on POSIX systems) if there were no errors 141 | and 142 | with EXIT_FAILURE (1 on POSIX systems) if there were errors. 143 | Errors raised in interactive mode do not cause exits. 144 | .SH DIAGNOSTICS 145 | Error messages should be self explanatory. 146 | .SH "SEE ALSO" 147 | .BR luac (1) 148 | .br 149 | The documentation at lua.org, 150 | especially section 7 of the reference manual. 151 | .SH AUTHORS 152 | R. Ierusalimschy, 153 | L. H. de Figueiredo, 154 | W. Celes 155 | .\" EOF 156 | -------------------------------------------------------------------------------- /lua-5.4.7/doc/lua.css: -------------------------------------------------------------------------------- 1 | html { 2 | background-color: #F8F8F8 ; 3 | } 4 | 5 | body { 6 | background-color: #FFFFFF ; 7 | color: #000000 ; 8 | font-family: Helvetica, Arial, sans-serif ; 9 | text-align: justify ; 10 | line-height: 1.25 ; 11 | margin: 16px auto ; 12 | padding: 32px ; 13 | border: solid #ccc 1px ; 14 | border-radius: 20px ; 15 | max-width: 70em ; 16 | width: 90% ; 17 | } 18 | 19 | h1, h2, h3, h4 { 20 | color: #000080 ; 21 | font-family: Verdana, Geneva, sans-serif ; 22 | font-weight: normal ; 23 | font-style: normal ; 24 | text-align: left ; 25 | } 26 | 27 | h1 { 28 | font-size: 28pt ; 29 | } 30 | 31 | h1 img { 32 | vertical-align: text-bottom ; 33 | } 34 | 35 | h2:before { 36 | content: "\2756" ; 37 | padding-right: 0.5em ; 38 | } 39 | 40 | a { 41 | text-decoration: none ; 42 | } 43 | 44 | a:link { 45 | color: #000080 ; 46 | } 47 | 48 | a:link:hover, a:visited:hover { 49 | background-color: #D0D0FF ; 50 | color: #000080 ; 51 | border-radius: 4px ; 52 | } 53 | 54 | a:link:active, a:visited:active { 55 | color: #FF0000 ; 56 | } 57 | 58 | div.menubar { 59 | padding-bottom: 0.5em ; 60 | } 61 | 62 | p.menubar { 63 | margin-left: 2.5em ; 64 | } 65 | 66 | .menubar a:hover { 67 | margin: -3px -3px -3px -3px ; 68 | padding: 3px 3px 3px 3px ; 69 | border-radius: 4px ; 70 | } 71 | 72 | :target { 73 | background-color: #F0F0F0 ; 74 | margin: -8px ; 75 | padding: 8px ; 76 | border-radius: 8px ; 77 | outline: none ; 78 | } 79 | 80 | hr { 81 | display: none ; 82 | } 83 | 84 | table hr { 85 | background-color: #a0a0a0 ; 86 | color: #a0a0a0 ; 87 | border: 0 ; 88 | height: 1px ; 89 | display: block ; 90 | } 91 | 92 | .footer { 93 | color: gray ; 94 | font-size: x-small ; 95 | text-transform: lowercase ; 96 | } 97 | 98 | input[type=text] { 99 | border: solid #a0a0a0 2px ; 100 | border-radius: 2em ; 101 | background-image: url('images/search.png') ; 102 | background-repeat: no-repeat ; 103 | background-position: 4px center ; 104 | padding-left: 20px ; 105 | height: 2em ; 106 | } 107 | 108 | pre.session { 109 | background-color: #F8F8F8 ; 110 | padding: 1em ; 111 | border-radius: 8px ; 112 | } 113 | 114 | table { 115 | border: none ; 116 | border-spacing: 0 ; 117 | border-collapse: collapse ; 118 | } 119 | 120 | td { 121 | padding: 0 ; 122 | margin: 0 ; 123 | } 124 | 125 | td.gutter { 126 | width: 4% ; 127 | } 128 | 129 | table.columns td { 130 | vertical-align: top ; 131 | padding-bottom: 1em ; 132 | text-align: justify ; 133 | line-height: 1.25 ; 134 | } 135 | 136 | table.book td { 137 | vertical-align: top ; 138 | } 139 | 140 | table.book td.cover { 141 | padding-right: 1em ; 142 | } 143 | 144 | table.book img { 145 | border: solid #000080 1px ; 146 | border-radius: 2px ; 147 | } 148 | 149 | table.book span { 150 | font-size: small ; 151 | text-align: left ; 152 | display: block ; 153 | margin-top: 0.25em ; 154 | } 155 | 156 | p.logos a:link:hover, p.logos a:visited:hover { 157 | background-color: inherit ; 158 | } 159 | 160 | img { 161 | background-color: white ; 162 | } 163 | -------------------------------------------------------------------------------- /lua-5.4.7/doc/luac.1: -------------------------------------------------------------------------------- 1 | .\" $Id: luac.man,v 1.29 2011/11/16 13:53:40 lhf Exp $ 2 | .TH LUAC 1 "$Date: 2011/11/16 13:53:40 $" 3 | .SH NAME 4 | luac \- Lua compiler 5 | .SH SYNOPSIS 6 | .B luac 7 | [ 8 | .I options 9 | ] [ 10 | .I filenames 11 | ] 12 | .SH DESCRIPTION 13 | .B luac 14 | is the Lua compiler. 15 | It translates programs written in the Lua programming language 16 | into binary files containing precompiled chunks 17 | that can be later loaded and executed. 18 | .LP 19 | The main advantages of precompiling chunks are: 20 | faster loading, 21 | protecting source code from accidental user changes, 22 | and 23 | off-line syntax checking. 24 | Precompiling does not imply faster execution 25 | because in Lua chunks are always compiled into bytecodes before being executed. 26 | .B luac 27 | simply allows those bytecodes to be saved in a file for later execution. 28 | Precompiled chunks are not necessarily smaller than the corresponding source. 29 | The main goal in precompiling is faster loading. 30 | .LP 31 | In the command line, 32 | you can mix 33 | text files containing Lua source and 34 | binary files containing precompiled chunks. 35 | .B luac 36 | produces a single output file containing the combined bytecodes 37 | for all files given. 38 | Executing the combined file is equivalent to executing the given files. 39 | By default, 40 | the output file is named 41 | .BR luac.out , 42 | but you can change this with the 43 | .B \-o 44 | option. 45 | .LP 46 | Precompiled chunks are 47 | .I not 48 | portable across different architectures. 49 | Moreover, 50 | the internal format of precompiled chunks 51 | is likely to change when a new version of Lua is released. 52 | Make sure you save the source files of all Lua programs that you precompile. 53 | .LP 54 | .SH OPTIONS 55 | .TP 56 | .B \-l 57 | produce a listing of the compiled bytecode for Lua's virtual machine. 58 | Listing bytecodes is useful to learn about Lua's virtual machine. 59 | If no files are given, then 60 | .B luac 61 | loads 62 | .B luac.out 63 | and lists its contents. 64 | Use 65 | .B \-l \-l 66 | for a full listing. 67 | .TP 68 | .BI \-o " file" 69 | output to 70 | .IR file , 71 | instead of the default 72 | .BR luac.out . 73 | (You can use 74 | .B "'\-'" 75 | for standard output, 76 | but not on platforms that open standard output in text mode.) 77 | The output file may be one of the given files because 78 | all files are loaded before the output file is written. 79 | Be careful not to overwrite precious files. 80 | .TP 81 | .B \-p 82 | load files but do not generate any output file. 83 | Used mainly for syntax checking and for testing precompiled chunks: 84 | corrupted files will probably generate errors when loaded. 85 | If no files are given, then 86 | .B luac 87 | loads 88 | .B luac.out 89 | and tests its contents. 90 | No messages are displayed if the file loads without errors. 91 | .TP 92 | .B \-s 93 | strip debug information before writing the output file. 94 | This saves some space in very large chunks, 95 | but if errors occur when running a stripped chunk, 96 | then the error messages may not contain the full information they usually do. 97 | In particular, 98 | line numbers and names of local variables are lost. 99 | .TP 100 | .B \-v 101 | show version information. 102 | .TP 103 | .B \-\- 104 | stop handling options. 105 | .TP 106 | .B \- 107 | stop handling options and process standard input. 108 | .SH "SEE ALSO" 109 | .BR lua (1) 110 | .br 111 | The documentation at lua.org. 112 | .SH DIAGNOSTICS 113 | Error messages should be self explanatory. 114 | .SH AUTHORS 115 | R. Ierusalimschy, 116 | L. H. de Figueiredo, 117 | W. Celes 118 | .\" EOF 119 | -------------------------------------------------------------------------------- /lua-5.4.7/doc/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | color: gray ; 12 | float: right ; 13 | font-family: inherit ; 14 | font-style: normal ; 15 | font-size: small ; 16 | } 17 | 18 | h2:before { 19 | content: "" ; 20 | padding-right: 0em ; 21 | } 22 | -------------------------------------------------------------------------------- /lua-5.4.7/include/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /lua-5.4.7/include/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /lua-5.4.7/src/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for building Lua 2 | # See ../doc/readme.html for installation and customization instructions. 3 | 4 | # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= 5 | 6 | # Your platform. See PLATS for possible values. 7 | PLAT= guess 8 | 9 | CC= gcc -std=gnu99 10 | CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS) 11 | LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) 12 | LIBS= -lm $(SYSLIBS) $(MYLIBS) 13 | 14 | AR= ar rcu 15 | RANLIB= ranlib 16 | RM= rm -f 17 | UNAME= uname 18 | 19 | SYSCFLAGS= 20 | SYSLDFLAGS= 21 | SYSLIBS= 22 | 23 | MYCFLAGS= 24 | MYLDFLAGS= 25 | MYLIBS= 26 | MYOBJS= 27 | 28 | # Special flags for compiler modules; -Os reduces code size. 29 | CMCFLAGS= 30 | 31 | # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= 32 | 33 | PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris 34 | 35 | LUA_A= liblua.a 36 | CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o 37 | LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o 38 | BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) 39 | 40 | LUA_T= lua 41 | LUA_O= lua.o 42 | 43 | LUAC_T= luac 44 | LUAC_O= luac.o 45 | 46 | ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O) 47 | ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) 48 | ALL_A= $(LUA_A) 49 | 50 | # Targets start here. 51 | default: $(PLAT) 52 | 53 | all: $(ALL_T) 54 | 55 | o: $(ALL_O) 56 | 57 | a: $(ALL_A) 58 | 59 | $(LUA_A): $(BASE_O) 60 | $(AR) $@ $(BASE_O) 61 | $(RANLIB) $@ 62 | 63 | $(LUA_T): $(LUA_O) $(LUA_A) 64 | $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) 65 | 66 | $(LUAC_T): $(LUAC_O) $(LUA_A) 67 | $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) 68 | 69 | test: 70 | ./$(LUA_T) -v 71 | 72 | clean: 73 | $(RM) $(ALL_T) $(ALL_O) 74 | 75 | depend: 76 | @$(CC) $(CFLAGS) -MM l*.c 77 | 78 | echo: 79 | @echo "PLAT= $(PLAT)" 80 | @echo "CC= $(CC)" 81 | @echo "CFLAGS= $(CFLAGS)" 82 | @echo "LDFLAGS= $(LDFLAGS)" 83 | @echo "LIBS= $(LIBS)" 84 | @echo "AR= $(AR)" 85 | @echo "RANLIB= $(RANLIB)" 86 | @echo "RM= $(RM)" 87 | @echo "UNAME= $(UNAME)" 88 | 89 | # Convenience targets for popular platforms. 90 | ALL= all 91 | 92 | help: 93 | @echo "Do 'make PLATFORM' where PLATFORM is one of these:" 94 | @echo " $(PLATS)" 95 | @echo "See doc/readme.html for complete instructions." 96 | 97 | guess: 98 | @echo Guessing `$(UNAME)` 99 | @$(MAKE) `$(UNAME)` 100 | 101 | AIX aix: 102 | $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall" 103 | 104 | bsd: 105 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E" 106 | 107 | c89: 108 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89" 109 | @echo '' 110 | @echo '*** C89 does not guarantee 64-bit integers for Lua.' 111 | @echo '*** Make sure to compile all external Lua libraries' 112 | @echo '*** with LUA_USE_C89 to ensure consistency' 113 | @echo '' 114 | 115 | FreeBSD NetBSD OpenBSD freebsd: 116 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc" 117 | 118 | generic: $(ALL) 119 | 120 | ios: 121 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_IOS" 122 | 123 | Linux linux: linux-noreadline 124 | 125 | linux-noreadline: 126 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl" 127 | 128 | linux-readline: 129 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE" SYSLIBS="-Wl,-E -ldl -lreadline" 130 | 131 | Darwin macos macosx: 132 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" SYSLIBS="-lreadline" 133 | 134 | mingw: 135 | $(MAKE) "LUA_A=lua54.dll" "LUA_T=lua.exe" \ 136 | "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ 137 | "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe 138 | $(MAKE) "LUAC_T=luac.exe" luac.exe 139 | 140 | posix: 141 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" 142 | 143 | SunOS solaris: 144 | $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl" 145 | 146 | # Targets that do not create files (not all makes understand .PHONY). 147 | .PHONY: all $(PLATS) help test clean default o a depend echo 148 | 149 | # Compiler modules may use special flags. 150 | llex.o: 151 | $(CC) $(CFLAGS) $(CMCFLAGS) -c llex.c 152 | 153 | lparser.o: 154 | $(CC) $(CFLAGS) $(CMCFLAGS) -c lparser.c 155 | 156 | lcode.o: 157 | $(CC) $(CFLAGS) $(CMCFLAGS) -c lcode.c 158 | 159 | # DO NOT DELETE 160 | 161 | lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 162 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lstring.h \ 163 | ltable.h lundump.h lvm.h 164 | lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h 165 | lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 166 | lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ 167 | llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ 168 | ldo.h lgc.h lstring.h ltable.h lvm.h 169 | lcorolib.o: lcorolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 170 | lctype.o: lctype.c lprefix.h lctype.h lua.h luaconf.h llimits.h 171 | ldblib.o: ldblib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 172 | ldebug.o: ldebug.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 173 | lobject.h ltm.h lzio.h lmem.h lcode.h llex.h lopcodes.h lparser.h \ 174 | ldebug.h ldo.h lfunc.h lstring.h lgc.h ltable.h lvm.h 175 | ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 176 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h lopcodes.h \ 177 | lparser.h lstring.h ltable.h lundump.h lvm.h 178 | ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \ 179 | ltm.h lzio.h lmem.h lundump.h 180 | lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 181 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h 182 | lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 183 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h 184 | linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h 185 | liolib.o: liolib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 186 | llex.o: llex.c lprefix.h lua.h luaconf.h lctype.h llimits.h ldebug.h \ 187 | lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lgc.h llex.h lparser.h \ 188 | lstring.h ltable.h 189 | lmathlib.o: lmathlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 190 | lmem.o: lmem.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 191 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h 192 | loadlib.o: loadlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 193 | lobject.o: lobject.c lprefix.h lua.h luaconf.h lctype.h llimits.h \ 194 | ldebug.h lstate.h lobject.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h \ 195 | lvm.h 196 | lopcodes.o: lopcodes.c lprefix.h lopcodes.h llimits.h lua.h luaconf.h 197 | loslib.o: loslib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 198 | lparser.o: lparser.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ 199 | llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ 200 | ldo.h lfunc.h lstring.h lgc.h ltable.h 201 | lstate.o: lstate.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ 202 | lobject.h ltm.h lzio.h lmem.h ldebug.h ldo.h lfunc.h lgc.h llex.h \ 203 | lstring.h ltable.h 204 | lstring.o: lstring.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ 205 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h 206 | lstrlib.o: lstrlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 207 | ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 208 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h 209 | ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 210 | ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 211 | llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h 212 | lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 213 | luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h ldebug.h lstate.h \ 214 | lobject.h llimits.h ltm.h lzio.h lmem.h lopcodes.h lopnames.h lundump.h 215 | lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ 216 | lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ 217 | lundump.h 218 | lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h 219 | lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ 220 | llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \ 221 | ltable.h lvm.h ljumptab.h 222 | lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ 223 | lobject.h ltm.h lzio.h 224 | 225 | # (end of Makefile) 226 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* Increments 'L->top.p', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top.p++; \ 17 | api_check(L, L->top.p <= L->ci->top.p, \ 18 | "stack overflow");} 19 | 20 | 21 | /* 22 | ** If a call returns too many multiple returns, the callee may not have 23 | ** stack space to accommodate all results. In this case, this macro 24 | ** increases its stack space ('L->ci->top.p'). 25 | */ 26 | #define adjustresults(L,nres) \ 27 | { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \ 28 | L->ci->top.p = L->top.p; } 29 | 30 | 31 | /* Ensure the stack has at least 'n' elements */ 32 | #define api_checknelems(L,n) \ 33 | api_check(L, (n) < (L->top.p - L->ci->func.p), \ 34 | "not enough elements in the stack") 35 | 36 | 37 | /* 38 | ** To reduce the overhead of returning from C functions, the presence of 39 | ** to-be-closed variables in these functions is coded in the CallInfo's 40 | ** field 'nresults', in a way that functions with no to-be-closed variables 41 | ** with zero, one, or "all" wanted results have no overhead. Functions 42 | ** with other number of wanted results, as well as functions with 43 | ** variables to be closed, have an extra check. 44 | */ 45 | 46 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 47 | 48 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 49 | #define codeNresults(n) (-(n) - 3) 50 | #define decodeNresults(n) (-(n) - 3) 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | /* arithmetic operators */ 28 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 29 | OPR_DIV, OPR_IDIV, 30 | /* bitwise operators */ 31 | OPR_BAND, OPR_BOR, OPR_BXOR, 32 | OPR_SHL, OPR_SHR, 33 | /* string operator */ 34 | OPR_CONCAT, 35 | /* comparison operators */ 36 | OPR_EQ, OPR_LT, OPR_LE, 37 | OPR_NE, OPR_GT, OPR_GE, 38 | /* logical operators */ 39 | OPR_AND, OPR_OR, 40 | OPR_NOBINOPR 41 | } BinOpr; 42 | 43 | 44 | /* true if operation is foldable (that is, it is arithmetic or bitwise) */ 45 | #define foldbinop(op) ((op) <= OPR_SHR) 46 | 47 | 48 | #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0) 49 | 50 | 51 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 52 | 53 | 54 | /* get (pointer to) instruction of given 'expdesc' */ 55 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 56 | 57 | 58 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 59 | 60 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 61 | 62 | LUAI_FUNC int luaK_code (FuncState *fs, Instruction i); 63 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 64 | LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, 65 | int B, int C, int k); 66 | LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v); 67 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 68 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 69 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 70 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 71 | LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n); 72 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 73 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 74 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 75 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 76 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 77 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 78 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 79 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 80 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 81 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 82 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 83 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 84 | LUAI_FUNC int luaK_jump (FuncState *fs); 85 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 86 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 87 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 88 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 89 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 90 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 91 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 92 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 93 | expdesc *v2, int line); 94 | LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc, 95 | int ra, int asize, int hsize); 96 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 97 | LUAI_FUNC void luaK_finish (FuncState *fs); 98 | LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); 99 | 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lcorolib.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcorolib.c $ 3 | ** Coroutine Library 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lcorolib_c 8 | #define LUA_LIB 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "lauxlib.h" 18 | #include "lualib.h" 19 | 20 | 21 | static lua_State *getco (lua_State *L) { 22 | lua_State *co = lua_tothread(L, 1); 23 | luaL_argexpected(L, co, 1, "thread"); 24 | return co; 25 | } 26 | 27 | 28 | /* 29 | ** Resumes a coroutine. Returns the number of results for non-error 30 | ** cases or -1 for errors. 31 | */ 32 | static int auxresume (lua_State *L, lua_State *co, int narg) { 33 | int status, nres; 34 | if (l_unlikely(!lua_checkstack(co, narg))) { 35 | lua_pushliteral(L, "too many arguments to resume"); 36 | return -1; /* error flag */ 37 | } 38 | lua_xmove(L, co, narg); 39 | status = lua_resume(co, L, narg, &nres); 40 | if (l_likely(status == LUA_OK || status == LUA_YIELD)) { 41 | if (l_unlikely(!lua_checkstack(L, nres + 1))) { 42 | lua_pop(co, nres); /* remove results anyway */ 43 | lua_pushliteral(L, "too many results to resume"); 44 | return -1; /* error flag */ 45 | } 46 | lua_xmove(co, L, nres); /* move yielded values */ 47 | return nres; 48 | } 49 | else { 50 | lua_xmove(co, L, 1); /* move error message */ 51 | return -1; /* error flag */ 52 | } 53 | } 54 | 55 | 56 | static int luaB_coresume (lua_State *L) { 57 | lua_State *co = getco(L); 58 | int r; 59 | r = auxresume(L, co, lua_gettop(L) - 1); 60 | if (l_unlikely(r < 0)) { 61 | lua_pushboolean(L, 0); 62 | lua_insert(L, -2); 63 | return 2; /* return false + error message */ 64 | } 65 | else { 66 | lua_pushboolean(L, 1); 67 | lua_insert(L, -(r + 1)); 68 | return r + 1; /* return true + 'resume' returns */ 69 | } 70 | } 71 | 72 | 73 | static int luaB_auxwrap (lua_State *L) { 74 | lua_State *co = lua_tothread(L, lua_upvalueindex(1)); 75 | int r = auxresume(L, co, lua_gettop(L)); 76 | if (l_unlikely(r < 0)) { /* error? */ 77 | int stat = lua_status(co); 78 | if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */ 79 | stat = lua_closethread(co, L); /* close its tbc variables */ 80 | lua_assert(stat != LUA_OK); 81 | lua_xmove(co, L, 1); /* move error message to the caller */ 82 | } 83 | if (stat != LUA_ERRMEM && /* not a memory error and ... */ 84 | lua_type(L, -1) == LUA_TSTRING) { /* ... error object is a string? */ 85 | luaL_where(L, 1); /* add extra info, if available */ 86 | lua_insert(L, -2); 87 | lua_concat(L, 2); 88 | } 89 | return lua_error(L); /* propagate error */ 90 | } 91 | return r; 92 | } 93 | 94 | 95 | static int luaB_cocreate (lua_State *L) { 96 | lua_State *NL; 97 | luaL_checktype(L, 1, LUA_TFUNCTION); 98 | NL = lua_newthread(L); 99 | lua_pushvalue(L, 1); /* move function to top */ 100 | lua_xmove(L, NL, 1); /* move function from L to NL */ 101 | return 1; 102 | } 103 | 104 | 105 | static int luaB_cowrap (lua_State *L) { 106 | luaB_cocreate(L); 107 | lua_pushcclosure(L, luaB_auxwrap, 1); 108 | return 1; 109 | } 110 | 111 | 112 | static int luaB_yield (lua_State *L) { 113 | return lua_yield(L, lua_gettop(L)); 114 | } 115 | 116 | 117 | #define COS_RUN 0 118 | #define COS_DEAD 1 119 | #define COS_YIELD 2 120 | #define COS_NORM 3 121 | 122 | 123 | static const char *const statname[] = 124 | {"running", "dead", "suspended", "normal"}; 125 | 126 | 127 | static int auxstatus (lua_State *L, lua_State *co) { 128 | if (L == co) return COS_RUN; 129 | else { 130 | switch (lua_status(co)) { 131 | case LUA_YIELD: 132 | return COS_YIELD; 133 | case LUA_OK: { 134 | lua_Debug ar; 135 | if (lua_getstack(co, 0, &ar)) /* does it have frames? */ 136 | return COS_NORM; /* it is running */ 137 | else if (lua_gettop(co) == 0) 138 | return COS_DEAD; 139 | else 140 | return COS_YIELD; /* initial state */ 141 | } 142 | default: /* some error occurred */ 143 | return COS_DEAD; 144 | } 145 | } 146 | } 147 | 148 | 149 | static int luaB_costatus (lua_State *L) { 150 | lua_State *co = getco(L); 151 | lua_pushstring(L, statname[auxstatus(L, co)]); 152 | return 1; 153 | } 154 | 155 | 156 | static int luaB_yieldable (lua_State *L) { 157 | lua_State *co = lua_isnone(L, 1) ? L : getco(L); 158 | lua_pushboolean(L, lua_isyieldable(co)); 159 | return 1; 160 | } 161 | 162 | 163 | static int luaB_corunning (lua_State *L) { 164 | int ismain = lua_pushthread(L); 165 | lua_pushboolean(L, ismain); 166 | return 2; 167 | } 168 | 169 | 170 | static int luaB_close (lua_State *L) { 171 | lua_State *co = getco(L); 172 | int status = auxstatus(L, co); 173 | switch (status) { 174 | case COS_DEAD: case COS_YIELD: { 175 | status = lua_closethread(co, L); 176 | if (status == LUA_OK) { 177 | lua_pushboolean(L, 1); 178 | return 1; 179 | } 180 | else { 181 | lua_pushboolean(L, 0); 182 | lua_xmove(co, L, 1); /* move error message */ 183 | return 2; 184 | } 185 | } 186 | default: /* normal or running coroutine */ 187 | return luaL_error(L, "cannot close a %s coroutine", statname[status]); 188 | } 189 | } 190 | 191 | 192 | static const luaL_Reg co_funcs[] = { 193 | {"create", luaB_cocreate}, 194 | {"resume", luaB_coresume}, 195 | {"running", luaB_corunning}, 196 | {"status", luaB_costatus}, 197 | {"wrap", luaB_cowrap}, 198 | {"yield", luaB_yield}, 199 | {"isyieldable", luaB_yieldable}, 200 | {"close", luaB_close}, 201 | {NULL, NULL} 202 | }; 203 | 204 | 205 | 206 | LUAMOD_API int luaopen_coroutine (lua_State *L) { 207 | luaL_newlib(L, co_funcs); 208 | return 1; 209 | } 210 | 211 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | 20 | #if defined (LUA_UCID) /* accept UniCode IDentifiers? */ 21 | /* consider all non-ascii codepoints to be alphabetic */ 22 | #define NONA 0x01 23 | #else 24 | #define NONA 0x00 /* default */ 25 | #endif 26 | 27 | 28 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 29 | 0x00, /* EOZ */ 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 31 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 35 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 36 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 37 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 38 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 39 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 40 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 41 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 42 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 43 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 44 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 45 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 46 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */ 47 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 48 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */ 49 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 50 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */ 51 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 52 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */ 53 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 54 | 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */ 55 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 56 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */ 57 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 58 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */ 59 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 60 | NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */ 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 62 | }; 63 | 64 | #endif /* } */ 65 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua. 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | 65 | /* 66 | ** In ASCII, this 'ltolower' is correct for alphabetic characters and 67 | ** for '.'. That is enough for Lua needs. ('check_exp' ensures that 68 | ** the character either is an upper-case letter or is unchanged by 69 | ** the transformation, which holds for lower-case letters and '.'.) 70 | */ 71 | #define ltolower(c) \ 72 | check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \ 73 | (c) | ('A' ^ 'a')) 74 | 75 | 76 | /* one entry for each character and for -1 (EOZ) */ 77 | LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];) 78 | 79 | 80 | #else /* }{ */ 81 | 82 | /* 83 | ** use standard C ctypes 84 | */ 85 | 86 | #include 87 | 88 | 89 | #define lislalpha(c) (isalpha(c) || (c) == '_') 90 | #define lislalnum(c) (isalnum(c) || (c) == '_') 91 | #define lisdigit(c) (isdigit(c)) 92 | #define lisspace(c) (isspace(c)) 93 | #define lisprint(c) (isprint(c)) 94 | #define lisxdigit(c) (isxdigit(c)) 95 | 96 | #define ltolower(c) (tolower(c)) 97 | 98 | #endif /* } */ 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /lua-5.4.7/src/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1) 15 | 16 | 17 | /* Active Lua function (given call info) */ 18 | #define ci_func(ci) (clLvalue(s2v((ci)->func.p))) 19 | 20 | 21 | #define resethookcount(L) (L->hookcount = L->basehookcount) 22 | 23 | /* 24 | ** mark for entries in 'lineinfo' array that has absolute information in 25 | ** 'abslineinfo' array 26 | */ 27 | #define ABSLINEINFO (-0x80) 28 | 29 | 30 | /* 31 | ** MAXimum number of successive Instructions WiTHout ABSolute line 32 | ** information. (A power of two allows fast divisions.) 33 | */ 34 | #if !defined(MAXIWTHABS) 35 | #define MAXIWTHABS 128 36 | #endif 37 | 38 | 39 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc); 40 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, 41 | StkId *pos); 42 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 43 | const char *opname); 44 | LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o); 45 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o, 46 | const char *what); 47 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 48 | const TValue *p2); 49 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 50 | const TValue *p2, 51 | const char *msg); 52 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 53 | const TValue *p2); 54 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 55 | const TValue *p2); 56 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 57 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 58 | TString *src, int line); 59 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 60 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); 61 | LUAI_FUNC int luaG_tracecall (lua_State *L); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /lua-5.4.7/src/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lobject.h" 13 | #include "lstate.h" 14 | #include "lzio.h" 15 | 16 | 17 | /* 18 | ** Macro to check stack size and grow stack if needed. Parameters 19 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 20 | ** stack across reallocations, doing the work only when needed. 21 | ** It also allows the running of one GC step when the stack is 22 | ** reallocated. 23 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 24 | ** at every check. 25 | */ 26 | #define luaD_checkstackaux(L,n,pre,pos) \ 27 | if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \ 28 | { pre; luaD_growstack(L, n, 1); pos; } \ 29 | else { condmovestack(L,pre,pos); } 30 | 31 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 32 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 33 | 34 | 35 | 36 | #define savestack(L,pt) (cast_charp(pt) - cast_charp(L->stack.p)) 37 | #define restorestack(L,n) cast(StkId, cast_charp(L->stack.p) + (n)) 38 | 39 | 40 | /* macro to check stack size, preserving 'p' */ 41 | #define checkstackp(L,n,p) \ 42 | luaD_checkstackaux(L, n, \ 43 | ptrdiff_t t__ = savestack(L, p), /* save 'p' */ \ 44 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ 45 | 46 | 47 | /* macro to check stack size and GC, preserving 'p' */ 48 | #define checkstackGCp(L,n,p) \ 49 | luaD_checkstackaux(L, n, \ 50 | ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \ 51 | luaC_checkGC(L), /* stack grow uses memory */ \ 52 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ 53 | 54 | 55 | /* macro to check stack size and GC */ 56 | #define checkstackGC(L,fsize) \ 57 | luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0) 58 | 59 | 60 | /* type of protected functions, to be ran by 'runprotected' */ 61 | typedef void (*Pfunc) (lua_State *L, void *ud); 62 | 63 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 64 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 65 | const char *mode); 66 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, 67 | int fTransfer, int nTransfer); 68 | LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); 69 | LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, 70 | int narg1, int delta); 71 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); 72 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 73 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 74 | LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status); 75 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 76 | ptrdiff_t oldtop, ptrdiff_t ef); 77 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); 78 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); 79 | LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror); 80 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 81 | LUAI_FUNC void luaD_inctop (lua_State *L); 82 | 83 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 84 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 85 | 86 | #endif 87 | 88 | -------------------------------------------------------------------------------- /lua-5.4.7/src/ldump.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldump.c $ 3 | ** save precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ldump_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | #include 15 | 16 | #include "lua.h" 17 | 18 | #include "lobject.h" 19 | #include "lstate.h" 20 | #include "lundump.h" 21 | 22 | 23 | typedef struct { 24 | lua_State *L; 25 | lua_Writer writer; 26 | void *data; 27 | int strip; 28 | int status; 29 | } DumpState; 30 | 31 | 32 | /* 33 | ** All high-level dumps go through dumpVector; you can change it to 34 | ** change the endianness of the result 35 | */ 36 | #define dumpVector(D,v,n) dumpBlock(D,v,(n)*sizeof((v)[0])) 37 | 38 | #define dumpLiteral(D, s) dumpBlock(D,s,sizeof(s) - sizeof(char)) 39 | 40 | 41 | static void dumpBlock (DumpState *D, const void *b, size_t size) { 42 | if (D->status == 0 && size > 0) { 43 | lua_unlock(D->L); 44 | D->status = (*D->writer)(D->L, b, size, D->data); 45 | lua_lock(D->L); 46 | } 47 | } 48 | 49 | 50 | #define dumpVar(D,x) dumpVector(D,&x,1) 51 | 52 | 53 | static void dumpByte (DumpState *D, int y) { 54 | lu_byte x = (lu_byte)y; 55 | dumpVar(D, x); 56 | } 57 | 58 | 59 | /* 60 | ** 'dumpSize' buffer size: each byte can store up to 7 bits. (The "+6" 61 | ** rounds up the division.) 62 | */ 63 | #define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7) 64 | 65 | static void dumpSize (DumpState *D, size_t x) { 66 | lu_byte buff[DIBS]; 67 | int n = 0; 68 | do { 69 | buff[DIBS - (++n)] = x & 0x7f; /* fill buffer in reverse order */ 70 | x >>= 7; 71 | } while (x != 0); 72 | buff[DIBS - 1] |= 0x80; /* mark last byte */ 73 | dumpVector(D, buff + DIBS - n, n); 74 | } 75 | 76 | 77 | static void dumpInt (DumpState *D, int x) { 78 | dumpSize(D, x); 79 | } 80 | 81 | 82 | static void dumpNumber (DumpState *D, lua_Number x) { 83 | dumpVar(D, x); 84 | } 85 | 86 | 87 | static void dumpInteger (DumpState *D, lua_Integer x) { 88 | dumpVar(D, x); 89 | } 90 | 91 | 92 | static void dumpString (DumpState *D, const TString *s) { 93 | if (s == NULL) 94 | dumpSize(D, 0); 95 | else { 96 | size_t size = tsslen(s); 97 | const char *str = getstr(s); 98 | dumpSize(D, size + 1); 99 | dumpVector(D, str, size); 100 | } 101 | } 102 | 103 | 104 | static void dumpCode (DumpState *D, const Proto *f) { 105 | dumpInt(D, f->sizecode); 106 | dumpVector(D, f->code, f->sizecode); 107 | } 108 | 109 | 110 | static void dumpFunction(DumpState *D, const Proto *f, TString *psource); 111 | 112 | static void dumpConstants (DumpState *D, const Proto *f) { 113 | int i; 114 | int n = f->sizek; 115 | dumpInt(D, n); 116 | for (i = 0; i < n; i++) { 117 | const TValue *o = &f->k[i]; 118 | int tt = ttypetag(o); 119 | dumpByte(D, tt); 120 | switch (tt) { 121 | case LUA_VNUMFLT: 122 | dumpNumber(D, fltvalue(o)); 123 | break; 124 | case LUA_VNUMINT: 125 | dumpInteger(D, ivalue(o)); 126 | break; 127 | case LUA_VSHRSTR: 128 | case LUA_VLNGSTR: 129 | dumpString(D, tsvalue(o)); 130 | break; 131 | default: 132 | lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE); 133 | } 134 | } 135 | } 136 | 137 | 138 | static void dumpProtos (DumpState *D, const Proto *f) { 139 | int i; 140 | int n = f->sizep; 141 | dumpInt(D, n); 142 | for (i = 0; i < n; i++) 143 | dumpFunction(D, f->p[i], f->source); 144 | } 145 | 146 | 147 | static void dumpUpvalues (DumpState *D, const Proto *f) { 148 | int i, n = f->sizeupvalues; 149 | dumpInt(D, n); 150 | for (i = 0; i < n; i++) { 151 | dumpByte(D, f->upvalues[i].instack); 152 | dumpByte(D, f->upvalues[i].idx); 153 | dumpByte(D, f->upvalues[i].kind); 154 | } 155 | } 156 | 157 | 158 | static void dumpDebug (DumpState *D, const Proto *f) { 159 | int i, n; 160 | n = (D->strip) ? 0 : f->sizelineinfo; 161 | dumpInt(D, n); 162 | dumpVector(D, f->lineinfo, n); 163 | n = (D->strip) ? 0 : f->sizeabslineinfo; 164 | dumpInt(D, n); 165 | for (i = 0; i < n; i++) { 166 | dumpInt(D, f->abslineinfo[i].pc); 167 | dumpInt(D, f->abslineinfo[i].line); 168 | } 169 | n = (D->strip) ? 0 : f->sizelocvars; 170 | dumpInt(D, n); 171 | for (i = 0; i < n; i++) { 172 | dumpString(D, f->locvars[i].varname); 173 | dumpInt(D, f->locvars[i].startpc); 174 | dumpInt(D, f->locvars[i].endpc); 175 | } 176 | n = (D->strip) ? 0 : f->sizeupvalues; 177 | dumpInt(D, n); 178 | for (i = 0; i < n; i++) 179 | dumpString(D, f->upvalues[i].name); 180 | } 181 | 182 | 183 | static void dumpFunction (DumpState *D, const Proto *f, TString *psource) { 184 | if (D->strip || f->source == psource) 185 | dumpString(D, NULL); /* no debug info or same source as its parent */ 186 | else 187 | dumpString(D, f->source); 188 | dumpInt(D, f->linedefined); 189 | dumpInt(D, f->lastlinedefined); 190 | dumpByte(D, f->numparams); 191 | dumpByte(D, f->is_vararg); 192 | dumpByte(D, f->maxstacksize); 193 | dumpCode(D, f); 194 | dumpConstants(D, f); 195 | dumpUpvalues(D, f); 196 | dumpProtos(D, f); 197 | dumpDebug(D, f); 198 | } 199 | 200 | 201 | static void dumpHeader (DumpState *D) { 202 | dumpLiteral(D, LUA_SIGNATURE); 203 | dumpByte(D, LUAC_VERSION); 204 | dumpByte(D, LUAC_FORMAT); 205 | dumpLiteral(D, LUAC_DATA); 206 | dumpByte(D, sizeof(Instruction)); 207 | dumpByte(D, sizeof(lua_Integer)); 208 | dumpByte(D, sizeof(lua_Number)); 209 | dumpInteger(D, LUAC_INT); 210 | dumpNumber(D, LUAC_NUM); 211 | } 212 | 213 | 214 | /* 215 | ** dump Lua function as precompiled chunk 216 | */ 217 | int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data, 218 | int strip) { 219 | DumpState D; 220 | D.L = L; 221 | D.writer = w; 222 | D.data = data; 223 | D.strip = strip; 224 | D.status = 0; 225 | dumpHeader(&D); 226 | dumpByte(&D, f->sizeupvalues); 227 | dumpFunction(&D, f, NULL); 228 | return D.status; 229 | } 230 | 231 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | #define upisopen(up) ((up)->v.p != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lgc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lgc.h $ 3 | ** Garbage Collector 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lgc_h 8 | #define lgc_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | /* 15 | ** Collectable objects may have one of three colors: white, which means 16 | ** the object is not marked; gray, which means the object is marked, but 17 | ** its references may be not marked; and black, which means that the 18 | ** object and all its references are marked. The main invariant of the 19 | ** garbage collector, while marking objects, is that a black object can 20 | ** never point to a white one. Moreover, any gray object must be in a 21 | ** "gray list" (gray, grayagain, weak, allweak, ephemeron) so that it 22 | ** can be visited again before finishing the collection cycle. (Open 23 | ** upvalues are an exception to this rule.) These lists have no meaning 24 | ** when the invariant is not being enforced (e.g., sweep phase). 25 | */ 26 | 27 | 28 | /* 29 | ** Possible states of the Garbage Collector 30 | */ 31 | #define GCSpropagate 0 32 | #define GCSenteratomic 1 33 | #define GCSatomic 2 34 | #define GCSswpallgc 3 35 | #define GCSswpfinobj 4 36 | #define GCSswptobefnz 5 37 | #define GCSswpend 6 38 | #define GCScallfin 7 39 | #define GCSpause 8 40 | 41 | 42 | #define issweepphase(g) \ 43 | (GCSswpallgc <= (g)->gcstate && (g)->gcstate <= GCSswpend) 44 | 45 | 46 | /* 47 | ** macro to tell when main invariant (white objects cannot point to black 48 | ** ones) must be kept. During a collection, the sweep 49 | ** phase may break the invariant, as objects turned white may point to 50 | ** still-black objects. The invariant is restored when sweep ends and 51 | ** all objects are white again. 52 | */ 53 | 54 | #define keepinvariant(g) ((g)->gcstate <= GCSatomic) 55 | 56 | 57 | /* 58 | ** some useful bit tricks 59 | */ 60 | #define resetbits(x,m) ((x) &= cast_byte(~(m))) 61 | #define setbits(x,m) ((x) |= (m)) 62 | #define testbits(x,m) ((x) & (m)) 63 | #define bitmask(b) (1<<(b)) 64 | #define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) 65 | #define l_setbit(x,b) setbits(x, bitmask(b)) 66 | #define resetbit(x,b) resetbits(x, bitmask(b)) 67 | #define testbit(x,b) testbits(x, bitmask(b)) 68 | 69 | 70 | /* 71 | ** Layout for bit use in 'marked' field. First three bits are 72 | ** used for object "age" in generational mode. Last bit is used 73 | ** by tests. 74 | */ 75 | #define WHITE0BIT 3 /* object is white (type 0) */ 76 | #define WHITE1BIT 4 /* object is white (type 1) */ 77 | #define BLACKBIT 5 /* object is black */ 78 | #define FINALIZEDBIT 6 /* object has been marked for finalization */ 79 | 80 | #define TESTBIT 7 81 | 82 | 83 | 84 | #define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) 85 | 86 | 87 | #define iswhite(x) testbits((x)->marked, WHITEBITS) 88 | #define isblack(x) testbit((x)->marked, BLACKBIT) 89 | #define isgray(x) /* neither white nor black */ \ 90 | (!testbits((x)->marked, WHITEBITS | bitmask(BLACKBIT))) 91 | 92 | #define tofinalize(x) testbit((x)->marked, FINALIZEDBIT) 93 | 94 | #define otherwhite(g) ((g)->currentwhite ^ WHITEBITS) 95 | #define isdeadm(ow,m) ((m) & (ow)) 96 | #define isdead(g,v) isdeadm(otherwhite(g), (v)->marked) 97 | 98 | #define changewhite(x) ((x)->marked ^= WHITEBITS) 99 | #define nw2black(x) \ 100 | check_exp(!iswhite(x), l_setbit((x)->marked, BLACKBIT)) 101 | 102 | #define luaC_white(g) cast_byte((g)->currentwhite & WHITEBITS) 103 | 104 | 105 | /* object age in generational mode */ 106 | #define G_NEW 0 /* created in current cycle */ 107 | #define G_SURVIVAL 1 /* created in previous cycle */ 108 | #define G_OLD0 2 /* marked old by frw. barrier in this cycle */ 109 | #define G_OLD1 3 /* first full cycle as old */ 110 | #define G_OLD 4 /* really old object (not to be visited) */ 111 | #define G_TOUCHED1 5 /* old object touched this cycle */ 112 | #define G_TOUCHED2 6 /* old object touched in previous cycle */ 113 | 114 | #define AGEBITS 7 /* all age bits (111) */ 115 | 116 | #define getage(o) ((o)->marked & AGEBITS) 117 | #define setage(o,a) ((o)->marked = cast_byte(((o)->marked & (~AGEBITS)) | a)) 118 | #define isold(o) (getage(o) > G_SURVIVAL) 119 | 120 | #define changeage(o,f,t) \ 121 | check_exp(getage(o) == (f), (o)->marked ^= ((f)^(t))) 122 | 123 | 124 | /* Default Values for GC parameters */ 125 | #define LUAI_GENMAJORMUL 100 126 | #define LUAI_GENMINORMUL 20 127 | 128 | /* wait memory to double before starting new cycle */ 129 | #define LUAI_GCPAUSE 200 130 | 131 | /* 132 | ** some gc parameters are stored divided by 4 to allow a maximum value 133 | ** up to 1023 in a 'lu_byte'. 134 | */ 135 | #define getgcparam(p) ((p) * 4) 136 | #define setgcparam(p,v) ((p) = (v) / 4) 137 | 138 | #define LUAI_GCMUL 100 139 | 140 | /* how much to allocate before next GC step (log2) */ 141 | #define LUAI_GCSTEPSIZE 13 /* 8 KB */ 142 | 143 | 144 | /* 145 | ** Check whether the declared GC mode is generational. While in 146 | ** generational mode, the collector can go temporarily to incremental 147 | ** mode to improve performance. This is signaled by 'g->lastatomic != 0'. 148 | */ 149 | #define isdecGCmodegen(g) (g->gckind == KGC_GEN || g->lastatomic != 0) 150 | 151 | 152 | /* 153 | ** Control when GC is running: 154 | */ 155 | #define GCSTPUSR 1 /* bit true when GC stopped by user */ 156 | #define GCSTPGC 2 /* bit true when GC stopped by itself */ 157 | #define GCSTPCLS 4 /* bit true when closing Lua state */ 158 | #define gcrunning(g) ((g)->gcstp == 0) 159 | 160 | 161 | /* 162 | ** Does one step of collection when debt becomes positive. 'pre'/'pos' 163 | ** allows some adjustments to be done only when needed. macro 164 | ** 'condchangemem' is used only for heavy tests (forcing a full 165 | ** GC cycle on every opportunity) 166 | */ 167 | #define luaC_condGC(L,pre,pos) \ 168 | { if (G(L)->GCdebt > 0) { pre; luaC_step(L); pos;}; \ 169 | condchangemem(L,pre,pos); } 170 | 171 | /* more often than not, 'pre'/'pos' are empty */ 172 | #define luaC_checkGC(L) luaC_condGC(L,(void)0,(void)0) 173 | 174 | 175 | #define luaC_objbarrier(L,p,o) ( \ 176 | (isblack(p) && iswhite(o)) ? \ 177 | luaC_barrier_(L,obj2gco(p),obj2gco(o)) : cast_void(0)) 178 | 179 | #define luaC_barrier(L,p,v) ( \ 180 | iscollectable(v) ? luaC_objbarrier(L,p,gcvalue(v)) : cast_void(0)) 181 | 182 | #define luaC_objbarrierback(L,p,o) ( \ 183 | (isblack(p) && iswhite(o)) ? luaC_barrierback_(L,p) : cast_void(0)) 184 | 185 | #define luaC_barrierback(L,p,v) ( \ 186 | iscollectable(v) ? luaC_objbarrierback(L, p, gcvalue(v)) : cast_void(0)) 187 | 188 | LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 189 | LUAI_FUNC void luaC_freeallobjects (lua_State *L); 190 | LUAI_FUNC void luaC_step (lua_State *L); 191 | LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 192 | LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 193 | LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 194 | LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, int tt, size_t sz, 195 | size_t offset); 196 | LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); 197 | LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); 198 | LUAI_FUNC void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt); 199 | LUAI_FUNC void luaC_changemode (lua_State *L, int newmode); 200 | 201 | 202 | #endif 203 | -------------------------------------------------------------------------------- /lua-5.4.7/src/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {LUA_GNAME, luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /lua-5.4.7/src/ljumptab.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ljumptab.h $ 3 | ** Jump Table for the Lua interpreter 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #undef vmdispatch 9 | #undef vmcase 10 | #undef vmbreak 11 | 12 | #define vmdispatch(x) goto *disptab[x]; 13 | 14 | #define vmcase(l) L_##l: 15 | 16 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i)); 17 | 18 | 19 | static const void *const disptab[NUM_OPCODES] = { 20 | 21 | #if 0 22 | ** you can update the following list with this command: 23 | ** 24 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h 25 | ** 26 | #endif 27 | 28 | &&L_OP_MOVE, 29 | &&L_OP_LOADI, 30 | &&L_OP_LOADF, 31 | &&L_OP_LOADK, 32 | &&L_OP_LOADKX, 33 | &&L_OP_LOADFALSE, 34 | &&L_OP_LFALSESKIP, 35 | &&L_OP_LOADTRUE, 36 | &&L_OP_LOADNIL, 37 | &&L_OP_GETUPVAL, 38 | &&L_OP_SETUPVAL, 39 | &&L_OP_GETTABUP, 40 | &&L_OP_GETTABLE, 41 | &&L_OP_GETI, 42 | &&L_OP_GETFIELD, 43 | &&L_OP_SETTABUP, 44 | &&L_OP_SETTABLE, 45 | &&L_OP_SETI, 46 | &&L_OP_SETFIELD, 47 | &&L_OP_NEWTABLE, 48 | &&L_OP_SELF, 49 | &&L_OP_ADDI, 50 | &&L_OP_ADDK, 51 | &&L_OP_SUBK, 52 | &&L_OP_MULK, 53 | &&L_OP_MODK, 54 | &&L_OP_POWK, 55 | &&L_OP_DIVK, 56 | &&L_OP_IDIVK, 57 | &&L_OP_BANDK, 58 | &&L_OP_BORK, 59 | &&L_OP_BXORK, 60 | &&L_OP_SHRI, 61 | &&L_OP_SHLI, 62 | &&L_OP_ADD, 63 | &&L_OP_SUB, 64 | &&L_OP_MUL, 65 | &&L_OP_MOD, 66 | &&L_OP_POW, 67 | &&L_OP_DIV, 68 | &&L_OP_IDIV, 69 | &&L_OP_BAND, 70 | &&L_OP_BOR, 71 | &&L_OP_BXOR, 72 | &&L_OP_SHL, 73 | &&L_OP_SHR, 74 | &&L_OP_MMBIN, 75 | &&L_OP_MMBINI, 76 | &&L_OP_MMBINK, 77 | &&L_OP_UNM, 78 | &&L_OP_BNOT, 79 | &&L_OP_NOT, 80 | &&L_OP_LEN, 81 | &&L_OP_CONCAT, 82 | &&L_OP_CLOSE, 83 | &&L_OP_TBC, 84 | &&L_OP_JMP, 85 | &&L_OP_EQ, 86 | &&L_OP_LT, 87 | &&L_OP_LE, 88 | &&L_OP_EQK, 89 | &&L_OP_EQI, 90 | &&L_OP_LTI, 91 | &&L_OP_LEI, 92 | &&L_OP_GTI, 93 | &&L_OP_GEI, 94 | &&L_OP_TEST, 95 | &&L_OP_TESTSET, 96 | &&L_OP_CALL, 97 | &&L_OP_TAILCALL, 98 | &&L_OP_RETURN, 99 | &&L_OP_RETURN0, 100 | &&L_OP_RETURN1, 101 | &&L_OP_FORLOOP, 102 | &&L_OP_FORPREP, 103 | &&L_OP_TFORPREP, 104 | &&L_OP_TFORCALL, 105 | &&L_OP_TFORLOOP, 106 | &&L_OP_SETLIST, 107 | &&L_OP_CLOSURE, 108 | &&L_OP_VARARG, 109 | &&L_OP_VARARGPREP, 110 | &&L_OP_EXTRAARG 111 | 112 | }; 113 | -------------------------------------------------------------------------------- /lua-5.4.7/src/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Single-char tokens (terminal symbols) are represented by their own 18 | ** numeric code. Other tokens start at the following value. 19 | */ 20 | #define FIRST_RESERVED (UCHAR_MAX + 1) 21 | 22 | 23 | #if !defined(LUA_ENV) 24 | #define LUA_ENV "_ENV" 25 | #endif 26 | 27 | 28 | /* 29 | * WARNING: if you change the order of this enumeration, 30 | * grep "ORDER RESERVED" 31 | */ 32 | enum RESERVED { 33 | /* terminal symbols denoted by reserved words */ 34 | TK_AND = FIRST_RESERVED, TK_BREAK, 35 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 36 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 37 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 38 | /* other terminal symbols */ 39 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 40 | TK_SHL, TK_SHR, 41 | TK_DBCOLON, TK_EOS, 42 | TK_FLT, TK_INT, TK_NAME, TK_STRING 43 | }; 44 | 45 | /* number of reserved words */ 46 | #define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1)) 47 | 48 | 49 | typedef union { 50 | lua_Number r; 51 | lua_Integer i; 52 | TString *ts; 53 | } SemInfo; /* semantics information */ 54 | 55 | 56 | typedef struct Token { 57 | int token; 58 | SemInfo seminfo; 59 | } Token; 60 | 61 | 62 | /* state of the lexer plus state of the parser when shared by all 63 | functions */ 64 | typedef struct LexState { 65 | int current; /* current character (charint) */ 66 | int linenumber; /* input line counter */ 67 | int lastline; /* line of last token 'consumed' */ 68 | Token t; /* current token */ 69 | Token lookahead; /* look ahead token */ 70 | struct FuncState *fs; /* current function (parser) */ 71 | struct lua_State *L; 72 | ZIO *z; /* input stream */ 73 | Mbuffer *buff; /* buffer for tokens */ 74 | Table *h; /* to avoid collection/reuse strings */ 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 76 | TString *source; /* current source name */ 77 | TString *envn; /* environment variable name */ 78 | } LexState; 79 | 80 | 81 | LUAI_FUNC void luaX_init (lua_State *L); 82 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 83 | TString *source, int firstchar); 84 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 85 | LUAI_FUNC void luaX_next (LexState *ls); 86 | LUAI_FUNC int luaX_lookahead (LexState *ls); 87 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 88 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 89 | 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.c $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lmem_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lgc.h" 20 | #include "lmem.h" 21 | #include "lobject.h" 22 | #include "lstate.h" 23 | 24 | 25 | 26 | /* 27 | ** About the realloc function: 28 | ** void *frealloc (void *ud, void *ptr, size_t osize, size_t nsize); 29 | ** ('osize' is the old size, 'nsize' is the new size) 30 | ** 31 | ** - frealloc(ud, p, x, 0) frees the block 'p' and returns NULL. 32 | ** Particularly, frealloc(ud, NULL, 0, 0) does nothing, 33 | ** which is equivalent to free(NULL) in ISO C. 34 | ** 35 | ** - frealloc(ud, NULL, x, s) creates a new block of size 's' 36 | ** (no matter 'x'). Returns NULL if it cannot create the new block. 37 | ** 38 | ** - otherwise, frealloc(ud, b, x, y) reallocates the block 'b' from 39 | ** size 'x' to size 'y'. Returns NULL if it cannot reallocate the 40 | ** block to the new size. 41 | */ 42 | 43 | 44 | /* 45 | ** Macro to call the allocation function. 46 | */ 47 | #define callfrealloc(g,block,os,ns) ((*g->frealloc)(g->ud, block, os, ns)) 48 | 49 | 50 | /* 51 | ** When an allocation fails, it will try again after an emergency 52 | ** collection, except when it cannot run a collection. The GC should 53 | ** not be called while the state is not fully built, as the collector 54 | ** is not yet fully initialized. Also, it should not be called when 55 | ** 'gcstopem' is true, because then the interpreter is in the middle of 56 | ** a collection step. 57 | */ 58 | #define cantryagain(g) (completestate(g) && !g->gcstopem) 59 | 60 | 61 | 62 | 63 | #if defined(EMERGENCYGCTESTS) 64 | /* 65 | ** First allocation will fail except when freeing a block (frees never 66 | ** fail) and when it cannot try again; this fail will trigger 'tryagain' 67 | ** and a full GC cycle at every allocation. 68 | */ 69 | static void *firsttry (global_State *g, void *block, size_t os, size_t ns) { 70 | if (ns > 0 && cantryagain(g)) 71 | return NULL; /* fail */ 72 | else /* normal allocation */ 73 | return callfrealloc(g, block, os, ns); 74 | } 75 | #else 76 | #define firsttry(g,block,os,ns) callfrealloc(g, block, os, ns) 77 | #endif 78 | 79 | 80 | 81 | 82 | 83 | /* 84 | ** {================================================================== 85 | ** Functions to allocate/deallocate arrays for the Parser 86 | ** =================================================================== 87 | */ 88 | 89 | /* 90 | ** Minimum size for arrays during parsing, to avoid overhead of 91 | ** reallocating to size 1, then 2, and then 4. All these arrays 92 | ** will be reallocated to exact sizes or erased when parsing ends. 93 | */ 94 | #define MINSIZEARRAY 4 95 | 96 | 97 | void *luaM_growaux_ (lua_State *L, void *block, int nelems, int *psize, 98 | int size_elems, int limit, const char *what) { 99 | void *newblock; 100 | int size = *psize; 101 | if (nelems + 1 <= size) /* does one extra element still fit? */ 102 | return block; /* nothing to be done */ 103 | if (size >= limit / 2) { /* cannot double it? */ 104 | if (l_unlikely(size >= limit)) /* cannot grow even a little? */ 105 | luaG_runerror(L, "too many %s (limit is %d)", what, limit); 106 | size = limit; /* still have at least one free place */ 107 | } 108 | else { 109 | size *= 2; 110 | if (size < MINSIZEARRAY) 111 | size = MINSIZEARRAY; /* minimum size */ 112 | } 113 | lua_assert(nelems + 1 <= size && size <= limit); 114 | /* 'limit' ensures that multiplication will not overflow */ 115 | newblock = luaM_saferealloc_(L, block, cast_sizet(*psize) * size_elems, 116 | cast_sizet(size) * size_elems); 117 | *psize = size; /* update only when everything else is OK */ 118 | return newblock; 119 | } 120 | 121 | 122 | /* 123 | ** In prototypes, the size of the array is also its number of 124 | ** elements (to save memory). So, if it cannot shrink an array 125 | ** to its number of elements, the only option is to raise an 126 | ** error. 127 | */ 128 | void *luaM_shrinkvector_ (lua_State *L, void *block, int *size, 129 | int final_n, int size_elem) { 130 | void *newblock; 131 | size_t oldsize = cast_sizet((*size) * size_elem); 132 | size_t newsize = cast_sizet(final_n * size_elem); 133 | lua_assert(newsize <= oldsize); 134 | newblock = luaM_saferealloc_(L, block, oldsize, newsize); 135 | *size = final_n; 136 | return newblock; 137 | } 138 | 139 | /* }================================================================== */ 140 | 141 | 142 | l_noret luaM_toobig (lua_State *L) { 143 | luaG_runerror(L, "memory allocation error: block too big"); 144 | } 145 | 146 | 147 | /* 148 | ** Free memory 149 | */ 150 | void luaM_free_ (lua_State *L, void *block, size_t osize) { 151 | global_State *g = G(L); 152 | lua_assert((osize == 0) == (block == NULL)); 153 | callfrealloc(g, block, osize, 0); 154 | g->GCdebt -= osize; 155 | } 156 | 157 | 158 | /* 159 | ** In case of allocation fail, this function will do an emergency 160 | ** collection to free some memory and then try the allocation again. 161 | */ 162 | static void *tryagain (lua_State *L, void *block, 163 | size_t osize, size_t nsize) { 164 | global_State *g = G(L); 165 | if (cantryagain(g)) { 166 | luaC_fullgc(L, 1); /* try to free some memory... */ 167 | return callfrealloc(g, block, osize, nsize); /* try again */ 168 | } 169 | else return NULL; /* cannot run an emergency collection */ 170 | } 171 | 172 | 173 | /* 174 | ** Generic allocation routine. 175 | */ 176 | void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { 177 | void *newblock; 178 | global_State *g = G(L); 179 | lua_assert((osize == 0) == (block == NULL)); 180 | newblock = firsttry(g, block, osize, nsize); 181 | if (l_unlikely(newblock == NULL && nsize > 0)) { 182 | newblock = tryagain(L, block, osize, nsize); 183 | if (newblock == NULL) /* still no memory? */ 184 | return NULL; /* do not update 'GCdebt' */ 185 | } 186 | lua_assert((nsize == 0) == (newblock == NULL)); 187 | g->GCdebt = (g->GCdebt + nsize) - osize; 188 | return newblock; 189 | } 190 | 191 | 192 | void *luaM_saferealloc_ (lua_State *L, void *block, size_t osize, 193 | size_t nsize) { 194 | void *newblock = luaM_realloc_(L, block, osize, nsize); 195 | if (l_unlikely(newblock == NULL && nsize > 0)) /* allocation failed? */ 196 | luaM_error(L); 197 | return newblock; 198 | } 199 | 200 | 201 | void *luaM_malloc_ (lua_State *L, size_t size, int tag) { 202 | if (size == 0) 203 | return NULL; /* that's all */ 204 | else { 205 | global_State *g = G(L); 206 | void *newblock = firsttry(g, NULL, tag, size); 207 | if (l_unlikely(newblock == NULL)) { 208 | newblock = tryagain(L, NULL, tag, size); 209 | if (newblock == NULL) 210 | luaM_error(L); 211 | } 212 | g->GCdebt += size; 213 | return newblock; 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | #define luaM_error(L) luaD_throw(L, LUA_ERRMEM) 18 | 19 | 20 | /* 21 | ** This macro tests whether it is safe to multiply 'n' by the size of 22 | ** type 't' without overflows. Because 'e' is always constant, it avoids 23 | ** the runtime division MAX_SIZET/(e). 24 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 25 | ** comparison avoids a runtime comparison when overflow cannot occur. 26 | ** The compiler should be able to optimize the real test by itself, but 27 | ** when it does it, it may give a warning about "comparison is always 28 | ** false due to limited range of data type"; the +1 tricks the compiler, 29 | ** avoiding this warning but also this optimization.) 30 | */ 31 | #define luaM_testsize(n,e) \ 32 | (sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e)) 33 | 34 | #define luaM_checksize(L,n,e) \ 35 | (luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0)) 36 | 37 | 38 | /* 39 | ** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that 40 | ** the result is not larger than 'n' and cannot overflow a 'size_t' 41 | ** when multiplied by the size of type 't'. (Assumes that 'n' is an 42 | ** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.) 43 | */ 44 | #define luaM_limitN(n,t) \ 45 | ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \ 46 | cast_uint((MAX_SIZET/sizeof(t)))) 47 | 48 | 49 | /* 50 | ** Arrays of chars do not need any test 51 | */ 52 | #define luaM_reallocvchar(L,b,on,n) \ 53 | cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 54 | 55 | #define luaM_freemem(L, b, s) luaM_free_(L, (b), (s)) 56 | #define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b))) 57 | #define luaM_freearray(L, b, n) luaM_free_(L, (b), (n)*sizeof(*(b))) 58 | 59 | #define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0)) 60 | #define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0)) 61 | #define luaM_newvectorchecked(L,n,t) \ 62 | (luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t)) 63 | 64 | #define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag) 65 | 66 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 67 | ((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \ 68 | luaM_limitN(limit,t),e))) 69 | 70 | #define luaM_reallocvector(L, v,oldn,n,t) \ 71 | (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \ 72 | cast_sizet(n) * sizeof(t)))) 73 | 74 | #define luaM_shrinkvector(L,v,size,fs,t) \ 75 | ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t)))) 76 | 77 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 78 | 79 | /* not to be called directly */ 80 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 81 | size_t size); 82 | LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize, 83 | size_t size); 84 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize); 85 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems, 86 | int *size, int size_elem, int limit, 87 | const char *what); 88 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem, 89 | int final_n, int size_elem); 90 | LUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag); 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lopcodes.h" 14 | 15 | 16 | /* ORDER OP */ 17 | 18 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 19 | /* MM OT IT T A mode opcode */ 20 | opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */ 21 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */ 22 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */ 23 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ 24 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ 25 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ 26 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ 27 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ 28 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ 29 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ 30 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETUPVAL */ 31 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABUP */ 32 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABLE */ 33 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETI */ 34 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETFIELD */ 35 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABUP */ 36 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABLE */ 37 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETI */ 38 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETFIELD */ 39 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NEWTABLE */ 40 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ 41 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ 42 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ 43 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ 44 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ 45 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */ 46 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */ 47 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */ 48 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */ 49 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */ 50 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */ 51 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXORK */ 52 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */ 53 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHLI */ 54 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADD */ 55 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */ 56 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */ 57 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */ 58 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */ 59 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */ 60 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */ 61 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */ 62 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */ 63 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXOR */ 64 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHL */ 65 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHR */ 66 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBIN */ 67 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINI*/ 68 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINK*/ 69 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_UNM */ 70 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BNOT */ 71 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NOT */ 72 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LEN */ 73 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_CONCAT */ 74 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_CLOSE */ 75 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TBC */ 76 | ,opmode(0, 0, 0, 0, 0, isJ) /* OP_JMP */ 77 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQ */ 78 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LT */ 79 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LE */ 80 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQK */ 81 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQI */ 82 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LTI */ 83 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LEI */ 84 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GTI */ 85 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GEI */ 86 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_TEST */ 87 | ,opmode(0, 0, 0, 1, 1, iABC) /* OP_TESTSET */ 88 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_CALL */ 89 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_TAILCALL */ 90 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_RETURN */ 91 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN0 */ 92 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN1 */ 93 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORLOOP */ 94 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORPREP */ 95 | ,opmode(0, 0, 0, 0, 0, iABx) /* OP_TFORPREP */ 96 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TFORCALL */ 97 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_TFORLOOP */ 98 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_SETLIST */ 99 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */ 100 | ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */ 101 | ,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */ 102 | ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ 103 | }; 104 | 105 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lparser.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lparser.h $ 3 | ** Lua Parser 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lparser_h 8 | #define lparser_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* 16 | ** Expression and variable descriptor. 17 | ** Code generation for variables and expressions can be delayed to allow 18 | ** optimizations; An 'expdesc' structure describes a potentially-delayed 19 | ** variable/expression. It has a description of its "main" value plus a 20 | ** list of conditional jumps that can also produce its value (generated 21 | ** by short-circuit operators 'and'/'or'). 22 | */ 23 | 24 | /* kinds of variables/expressions */ 25 | typedef enum { 26 | VVOID, /* when 'expdesc' describes the last expression of a list, 27 | this kind means an empty list (so, no expression) */ 28 | VNIL, /* constant nil */ 29 | VTRUE, /* constant true */ 30 | VFALSE, /* constant false */ 31 | VK, /* constant in 'k'; info = index of constant in 'k' */ 32 | VKFLT, /* floating constant; nval = numerical float value */ 33 | VKINT, /* integer constant; ival = numerical integer value */ 34 | VKSTR, /* string constant; strval = TString address; 35 | (string is fixed by the lexer) */ 36 | VNONRELOC, /* expression has its value in a fixed register; 37 | info = result register */ 38 | VLOCAL, /* local variable; var.ridx = register index; 39 | var.vidx = relative index in 'actvar.arr' */ 40 | VUPVAL, /* upvalue variable; info = index of upvalue in 'upvalues' */ 41 | VCONST, /* compile-time variable; 42 | info = absolute index in 'actvar.arr' */ 43 | VINDEXED, /* indexed variable; 44 | ind.t = table register; 45 | ind.idx = key's R index */ 46 | VINDEXUP, /* indexed upvalue; 47 | ind.t = table upvalue; 48 | ind.idx = key's K index */ 49 | VINDEXI, /* indexed variable with constant integer; 50 | ind.t = table register; 51 | ind.idx = key's value */ 52 | VINDEXSTR, /* indexed variable with literal string; 53 | ind.t = table register; 54 | ind.idx = key's K index */ 55 | VJMP, /* expression is a test/comparison; 56 | info = pc of corresponding jump instruction */ 57 | VRELOC, /* expression can put result in any register; 58 | info = instruction pc */ 59 | VCALL, /* expression is a function call; info = instruction pc */ 60 | VVARARG /* vararg expression; info = instruction pc */ 61 | } expkind; 62 | 63 | 64 | #define vkisvar(k) (VLOCAL <= (k) && (k) <= VINDEXSTR) 65 | #define vkisindexed(k) (VINDEXED <= (k) && (k) <= VINDEXSTR) 66 | 67 | 68 | typedef struct expdesc { 69 | expkind k; 70 | union { 71 | lua_Integer ival; /* for VKINT */ 72 | lua_Number nval; /* for VKFLT */ 73 | TString *strval; /* for VKSTR */ 74 | int info; /* for generic use */ 75 | struct { /* for indexed variables */ 76 | short idx; /* index (R or "long" K) */ 77 | lu_byte t; /* table (register or upvalue) */ 78 | } ind; 79 | struct { /* for local variables */ 80 | lu_byte ridx; /* register holding the variable */ 81 | unsigned short vidx; /* compiler index (in 'actvar.arr') */ 82 | } var; 83 | } u; 84 | int t; /* patch list of 'exit when true' */ 85 | int f; /* patch list of 'exit when false' */ 86 | } expdesc; 87 | 88 | 89 | /* kinds of variables */ 90 | #define VDKREG 0 /* regular */ 91 | #define RDKCONST 1 /* constant */ 92 | #define RDKTOCLOSE 2 /* to-be-closed */ 93 | #define RDKCTC 3 /* compile-time constant */ 94 | 95 | /* description of an active local variable */ 96 | typedef union Vardesc { 97 | struct { 98 | TValuefields; /* constant value (if it is a compile-time constant) */ 99 | lu_byte kind; 100 | lu_byte ridx; /* register holding the variable */ 101 | short pidx; /* index of the variable in the Proto's 'locvars' array */ 102 | TString *name; /* variable name */ 103 | } vd; 104 | TValue k; /* constant value (if any) */ 105 | } Vardesc; 106 | 107 | 108 | 109 | /* description of pending goto statements and label statements */ 110 | typedef struct Labeldesc { 111 | TString *name; /* label identifier */ 112 | int pc; /* position in code */ 113 | int line; /* line where it appeared */ 114 | lu_byte nactvar; /* number of active variables in that position */ 115 | lu_byte close; /* goto that escapes upvalues */ 116 | } Labeldesc; 117 | 118 | 119 | /* list of labels or gotos */ 120 | typedef struct Labellist { 121 | Labeldesc *arr; /* array */ 122 | int n; /* number of entries in use */ 123 | int size; /* array size */ 124 | } Labellist; 125 | 126 | 127 | /* dynamic structures used by the parser */ 128 | typedef struct Dyndata { 129 | struct { /* list of all active local variables */ 130 | Vardesc *arr; 131 | int n; 132 | int size; 133 | } actvar; 134 | Labellist gt; /* list of pending gotos */ 135 | Labellist label; /* list of active labels */ 136 | } Dyndata; 137 | 138 | 139 | /* control of blocks */ 140 | struct BlockCnt; /* defined in lparser.c */ 141 | 142 | 143 | /* state needed to generate code for a given function */ 144 | typedef struct FuncState { 145 | Proto *f; /* current function header */ 146 | struct FuncState *prev; /* enclosing function */ 147 | struct LexState *ls; /* lexical state */ 148 | struct BlockCnt *bl; /* chain of current blocks */ 149 | int pc; /* next position to code (equivalent to 'ncode') */ 150 | int lasttarget; /* 'label' of last 'jump label' */ 151 | int previousline; /* last line that was saved in 'lineinfo' */ 152 | int nk; /* number of elements in 'k' */ 153 | int np; /* number of elements in 'p' */ 154 | int nabslineinfo; /* number of elements in 'abslineinfo' */ 155 | int firstlocal; /* index of first local var (in Dyndata array) */ 156 | int firstlabel; /* index of first label (in 'dyd->label->arr') */ 157 | short ndebugvars; /* number of elements in 'f->locvars' */ 158 | lu_byte nactvar; /* number of active local variables */ 159 | lu_byte nups; /* number of upvalues */ 160 | lu_byte freereg; /* first free register */ 161 | lu_byte iwthabs; /* instructions issued since last absolute line info */ 162 | lu_byte needclose; /* function needs to close upvalues when returning */ 163 | } FuncState; 164 | 165 | 166 | LUAI_FUNC int luaY_nvarstack (FuncState *fs); 167 | LUAI_FUNC LClosure *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, 168 | Dyndata *dyd, const char *name, int firstchar); 169 | 170 | 171 | #endif 172 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lstring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.c $ 3 | ** String table (keeps all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lstring_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lmem.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | 24 | 25 | /* 26 | ** Maximum size for string table. 27 | */ 28 | #define MAXSTRTB cast_int(luaM_limitN(MAX_INT, TString*)) 29 | 30 | 31 | /* 32 | ** equality for long strings 33 | */ 34 | int luaS_eqlngstr (TString *a, TString *b) { 35 | size_t len = a->u.lnglen; 36 | lua_assert(a->tt == LUA_VLNGSTR && b->tt == LUA_VLNGSTR); 37 | return (a == b) || /* same instance or... */ 38 | ((len == b->u.lnglen) && /* equal length and ... */ 39 | (memcmp(getlngstr(a), getlngstr(b), len) == 0)); /* equal contents */ 40 | } 41 | 42 | 43 | unsigned int luaS_hash (const char *str, size_t l, unsigned int seed) { 44 | unsigned int h = seed ^ cast_uint(l); 45 | for (; l > 0; l--) 46 | h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); 47 | return h; 48 | } 49 | 50 | 51 | unsigned int luaS_hashlongstr (TString *ts) { 52 | lua_assert(ts->tt == LUA_VLNGSTR); 53 | if (ts->extra == 0) { /* no hash? */ 54 | size_t len = ts->u.lnglen; 55 | ts->hash = luaS_hash(getlngstr(ts), len, ts->hash); 56 | ts->extra = 1; /* now it has its hash */ 57 | } 58 | return ts->hash; 59 | } 60 | 61 | 62 | static void tablerehash (TString **vect, int osize, int nsize) { 63 | int i; 64 | for (i = osize; i < nsize; i++) /* clear new elements */ 65 | vect[i] = NULL; 66 | for (i = 0; i < osize; i++) { /* rehash old part of the array */ 67 | TString *p = vect[i]; 68 | vect[i] = NULL; 69 | while (p) { /* for each string in the list */ 70 | TString *hnext = p->u.hnext; /* save next */ 71 | unsigned int h = lmod(p->hash, nsize); /* new position */ 72 | p->u.hnext = vect[h]; /* chain it into array */ 73 | vect[h] = p; 74 | p = hnext; 75 | } 76 | } 77 | } 78 | 79 | 80 | /* 81 | ** Resize the string table. If allocation fails, keep the current size. 82 | ** (This can degrade performance, but any non-zero size should work 83 | ** correctly.) 84 | */ 85 | void luaS_resize (lua_State *L, int nsize) { 86 | stringtable *tb = &G(L)->strt; 87 | int osize = tb->size; 88 | TString **newvect; 89 | if (nsize < osize) /* shrinking table? */ 90 | tablerehash(tb->hash, osize, nsize); /* depopulate shrinking part */ 91 | newvect = luaM_reallocvector(L, tb->hash, osize, nsize, TString*); 92 | if (l_unlikely(newvect == NULL)) { /* reallocation failed? */ 93 | if (nsize < osize) /* was it shrinking table? */ 94 | tablerehash(tb->hash, nsize, osize); /* restore to original size */ 95 | /* leave table as it was */ 96 | } 97 | else { /* allocation succeeded */ 98 | tb->hash = newvect; 99 | tb->size = nsize; 100 | if (nsize > osize) 101 | tablerehash(newvect, osize, nsize); /* rehash for new size */ 102 | } 103 | } 104 | 105 | 106 | /* 107 | ** Clear API string cache. (Entries cannot be empty, so fill them with 108 | ** a non-collectable string.) 109 | */ 110 | void luaS_clearcache (global_State *g) { 111 | int i, j; 112 | for (i = 0; i < STRCACHE_N; i++) 113 | for (j = 0; j < STRCACHE_M; j++) { 114 | if (iswhite(g->strcache[i][j])) /* will entry be collected? */ 115 | g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */ 116 | } 117 | } 118 | 119 | 120 | /* 121 | ** Initialize the string table and the string cache 122 | */ 123 | void luaS_init (lua_State *L) { 124 | global_State *g = G(L); 125 | int i, j; 126 | stringtable *tb = &G(L)->strt; 127 | tb->hash = luaM_newvector(L, MINSTRTABSIZE, TString*); 128 | tablerehash(tb->hash, 0, MINSTRTABSIZE); /* clear array */ 129 | tb->size = MINSTRTABSIZE; 130 | /* pre-create memory-error message */ 131 | g->memerrmsg = luaS_newliteral(L, MEMERRMSG); 132 | luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */ 133 | for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */ 134 | for (j = 0; j < STRCACHE_M; j++) 135 | g->strcache[i][j] = g->memerrmsg; 136 | } 137 | 138 | 139 | 140 | /* 141 | ** creates a new string object 142 | */ 143 | static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) { 144 | TString *ts; 145 | GCObject *o; 146 | size_t totalsize; /* total size of TString object */ 147 | totalsize = sizelstring(l); 148 | o = luaC_newobj(L, tag, totalsize); 149 | ts = gco2ts(o); 150 | ts->hash = h; 151 | ts->extra = 0; 152 | getstr(ts)[l] = '\0'; /* ending 0 */ 153 | return ts; 154 | } 155 | 156 | 157 | TString *luaS_createlngstrobj (lua_State *L, size_t l) { 158 | TString *ts = createstrobj(L, l, LUA_VLNGSTR, G(L)->seed); 159 | ts->u.lnglen = l; 160 | ts->shrlen = 0xFF; /* signals that it is a long string */ 161 | return ts; 162 | } 163 | 164 | 165 | void luaS_remove (lua_State *L, TString *ts) { 166 | stringtable *tb = &G(L)->strt; 167 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; 168 | while (*p != ts) /* find previous element */ 169 | p = &(*p)->u.hnext; 170 | *p = (*p)->u.hnext; /* remove element from its list */ 171 | tb->nuse--; 172 | } 173 | 174 | 175 | static void growstrtab (lua_State *L, stringtable *tb) { 176 | if (l_unlikely(tb->nuse == MAX_INT)) { /* too many strings? */ 177 | luaC_fullgc(L, 1); /* try to free some... */ 178 | if (tb->nuse == MAX_INT) /* still too many? */ 179 | luaM_error(L); /* cannot even create a message... */ 180 | } 181 | if (tb->size <= MAXSTRTB / 2) /* can grow string table? */ 182 | luaS_resize(L, tb->size * 2); 183 | } 184 | 185 | 186 | /* 187 | ** Checks whether short string exists and reuses it or creates a new one. 188 | */ 189 | static TString *internshrstr (lua_State *L, const char *str, size_t l) { 190 | TString *ts; 191 | global_State *g = G(L); 192 | stringtable *tb = &g->strt; 193 | unsigned int h = luaS_hash(str, l, g->seed); 194 | TString **list = &tb->hash[lmod(h, tb->size)]; 195 | lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ 196 | for (ts = *list; ts != NULL; ts = ts->u.hnext) { 197 | if (l == ts->shrlen && (memcmp(str, getshrstr(ts), l * sizeof(char)) == 0)) { 198 | /* found! */ 199 | if (isdead(g, ts)) /* dead (but not collected yet)? */ 200 | changewhite(ts); /* resurrect it */ 201 | return ts; 202 | } 203 | } 204 | /* else must create a new string */ 205 | if (tb->nuse >= tb->size) { /* need to grow string table? */ 206 | growstrtab(L, tb); 207 | list = &tb->hash[lmod(h, tb->size)]; /* rehash with new size */ 208 | } 209 | ts = createstrobj(L, l, LUA_VSHRSTR, h); 210 | ts->shrlen = cast_byte(l); 211 | memcpy(getshrstr(ts), str, l * sizeof(char)); 212 | ts->u.hnext = *list; 213 | *list = ts; 214 | tb->nuse++; 215 | return ts; 216 | } 217 | 218 | 219 | /* 220 | ** new string (with explicit length) 221 | */ 222 | TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { 223 | if (l <= LUAI_MAXSHORTLEN) /* short string? */ 224 | return internshrstr(L, str, l); 225 | else { 226 | TString *ts; 227 | if (l_unlikely(l * sizeof(char) >= (MAX_SIZE - sizeof(TString)))) 228 | luaM_toobig(L); 229 | ts = luaS_createlngstrobj(L, l); 230 | memcpy(getlngstr(ts), str, l * sizeof(char)); 231 | return ts; 232 | } 233 | } 234 | 235 | 236 | /* 237 | ** Create or reuse a zero-terminated string, first checking in the 238 | ** cache (using the string address as a key). The cache can contain 239 | ** only zero-terminated strings, so it is safe to use 'strcmp' to 240 | ** check hits. 241 | */ 242 | TString *luaS_new (lua_State *L, const char *str) { 243 | unsigned int i = point2uint(str) % STRCACHE_N; /* hash */ 244 | int j; 245 | TString **p = G(L)->strcache[i]; 246 | for (j = 0; j < STRCACHE_M; j++) { 247 | if (strcmp(str, getstr(p[j])) == 0) /* hit? */ 248 | return p[j]; /* that is it */ 249 | } 250 | /* normal route */ 251 | for (j = STRCACHE_M - 1; j > 0; j--) 252 | p[j] = p[j - 1]; /* move out last element */ 253 | /* new element is first in the list */ 254 | p[0] = luaS_newlstr(L, str, strlen(str)); 255 | return p[0]; 256 | } 257 | 258 | 259 | Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue) { 260 | Udata *u; 261 | int i; 262 | GCObject *o; 263 | if (l_unlikely(s > MAX_SIZE - udatamemoffset(nuvalue))) 264 | luaM_toobig(L); 265 | o = luaC_newobj(L, LUA_VUSERDATA, sizeudata(nuvalue, s)); 266 | u = gco2u(o); 267 | u->len = s; 268 | u->nuvalue = nuvalue; 269 | u->metatable = NULL; 270 | for (i = 0; i < nuvalue; i++) 271 | setnilvalue(&u->uv[i].uv); 272 | return u; 273 | } 274 | 275 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lua-5.4.7/src/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->u.next) 16 | 17 | 18 | /* 19 | ** Clear all bits of fast-access metamethods, which means that the table 20 | ** may have any of these metamethods. (First access that fails after the 21 | ** clearing will set the bit again.) 22 | */ 23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags) 24 | 25 | 26 | /* true when 't' is using 'dummynode' as its hash part */ 27 | #define isdummy(t) ((t)->lastfree == NULL) 28 | 29 | 30 | /* allocated size for hash nodes */ 31 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 32 | 33 | 34 | /* returns the Node, given the value of a table entry */ 35 | #define nodefromval(v) cast(Node *, (v)) 36 | 37 | 38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 40 | TValue *value); 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 44 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, 45 | TValue *value); 46 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, 47 | const TValue *slot, TValue *value); 48 | LUAI_FUNC Table *luaH_new (lua_State *L); 49 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 50 | unsigned int nhsize); 51 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 52 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 53 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 54 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 55 | LUAI_FUNC unsigned int luaH_realasize (const Table *t); 56 | 57 | 58 | #if defined(LUA_DEBUG) 59 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 60 | #endif 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /lua-5.4.7/src/ltm.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.c $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define ltm_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "ldebug.h" 18 | #include "ldo.h" 19 | #include "lgc.h" 20 | #include "lobject.h" 21 | #include "lstate.h" 22 | #include "lstring.h" 23 | #include "ltable.h" 24 | #include "ltm.h" 25 | #include "lvm.h" 26 | 27 | 28 | static const char udatatypename[] = "userdata"; 29 | 30 | LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTYPES] = { 31 | "no value", 32 | "nil", "boolean", udatatypename, "number", 33 | "string", "table", "function", udatatypename, "thread", 34 | "upvalue", "proto" /* these last cases are used for tests only */ 35 | }; 36 | 37 | 38 | void luaT_init (lua_State *L) { 39 | static const char *const luaT_eventname[] = { /* ORDER TM */ 40 | "__index", "__newindex", 41 | "__gc", "__mode", "__len", "__eq", 42 | "__add", "__sub", "__mul", "__mod", "__pow", 43 | "__div", "__idiv", 44 | "__band", "__bor", "__bxor", "__shl", "__shr", 45 | "__unm", "__bnot", "__lt", "__le", 46 | "__concat", "__call", "__close" 47 | }; 48 | int i; 49 | for (i=0; itmname[i] = luaS_new(L, luaT_eventname[i]); 51 | luaC_fix(L, obj2gco(G(L)->tmname[i])); /* never collect these names */ 52 | } 53 | } 54 | 55 | 56 | /* 57 | ** function to be used with macro "fasttm": optimized for absence of 58 | ** tag methods 59 | */ 60 | const TValue *luaT_gettm (Table *events, TMS event, TString *ename) { 61 | const TValue *tm = luaH_getshortstr(events, ename); 62 | lua_assert(event <= TM_EQ); 63 | if (notm(tm)) { /* no tag method? */ 64 | events->flags |= cast_byte(1u<metatable; 76 | break; 77 | case LUA_TUSERDATA: 78 | mt = uvalue(o)->metatable; 79 | break; 80 | default: 81 | mt = G(L)->mt[ttype(o)]; 82 | } 83 | return (mt ? luaH_getshortstr(mt, G(L)->tmname[event]) : &G(L)->nilvalue); 84 | } 85 | 86 | 87 | /* 88 | ** Return the name of the type of an object. For tables and userdata 89 | ** with metatable, use their '__name' metafield, if present. 90 | */ 91 | const char *luaT_objtypename (lua_State *L, const TValue *o) { 92 | Table *mt; 93 | if ((ttistable(o) && (mt = hvalue(o)->metatable) != NULL) || 94 | (ttisfulluserdata(o) && (mt = uvalue(o)->metatable) != NULL)) { 95 | const TValue *name = luaH_getshortstr(mt, luaS_new(L, "__name")); 96 | if (ttisstring(name)) /* is '__name' a string? */ 97 | return getstr(tsvalue(name)); /* use it as type name */ 98 | } 99 | return ttypename(ttype(o)); /* else use standard type name */ 100 | } 101 | 102 | 103 | void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 104 | const TValue *p2, const TValue *p3) { 105 | StkId func = L->top.p; 106 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 107 | setobj2s(L, func + 1, p1); /* 1st argument */ 108 | setobj2s(L, func + 2, p2); /* 2nd argument */ 109 | setobj2s(L, func + 3, p3); /* 3rd argument */ 110 | L->top.p = func + 4; 111 | /* metamethod may yield only when called from Lua code */ 112 | if (isLuacode(L->ci)) 113 | luaD_call(L, func, 0); 114 | else 115 | luaD_callnoyield(L, func, 0); 116 | } 117 | 118 | 119 | void luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, 120 | const TValue *p2, StkId res) { 121 | ptrdiff_t result = savestack(L, res); 122 | StkId func = L->top.p; 123 | setobj2s(L, func, f); /* push function (assume EXTRA_STACK) */ 124 | setobj2s(L, func + 1, p1); /* 1st argument */ 125 | setobj2s(L, func + 2, p2); /* 2nd argument */ 126 | L->top.p += 3; 127 | /* metamethod may yield only when called from Lua code */ 128 | if (isLuacode(L->ci)) 129 | luaD_call(L, func, 1); 130 | else 131 | luaD_callnoyield(L, func, 1); 132 | res = restorestack(L, result); 133 | setobjs2s(L, res, --L->top.p); /* move result to its place */ 134 | } 135 | 136 | 137 | static int callbinTM (lua_State *L, const TValue *p1, const TValue *p2, 138 | StkId res, TMS event) { 139 | const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */ 140 | if (notm(tm)) 141 | tm = luaT_gettmbyobj(L, p2, event); /* try second operand */ 142 | if (notm(tm)) return 0; 143 | luaT_callTMres(L, tm, p1, p2, res); 144 | return 1; 145 | } 146 | 147 | 148 | void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 149 | StkId res, TMS event) { 150 | if (l_unlikely(!callbinTM(L, p1, p2, res, event))) { 151 | switch (event) { 152 | case TM_BAND: case TM_BOR: case TM_BXOR: 153 | case TM_SHL: case TM_SHR: case TM_BNOT: { 154 | if (ttisnumber(p1) && ttisnumber(p2)) 155 | luaG_tointerror(L, p1, p2); 156 | else 157 | luaG_opinterror(L, p1, p2, "perform bitwise operation on"); 158 | } 159 | /* calls never return, but to avoid warnings: *//* FALLTHROUGH */ 160 | default: 161 | luaG_opinterror(L, p1, p2, "perform arithmetic on"); 162 | } 163 | } 164 | } 165 | 166 | 167 | void luaT_tryconcatTM (lua_State *L) { 168 | StkId top = L->top.p; 169 | if (l_unlikely(!callbinTM(L, s2v(top - 2), s2v(top - 1), top - 2, 170 | TM_CONCAT))) 171 | luaG_concaterror(L, s2v(top - 2), s2v(top - 1)); 172 | } 173 | 174 | 175 | void luaT_trybinassocTM (lua_State *L, const TValue *p1, const TValue *p2, 176 | int flip, StkId res, TMS event) { 177 | if (flip) 178 | luaT_trybinTM(L, p2, p1, res, event); 179 | else 180 | luaT_trybinTM(L, p1, p2, res, event); 181 | } 182 | 183 | 184 | void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, 185 | int flip, StkId res, TMS event) { 186 | TValue aux; 187 | setivalue(&aux, i2); 188 | luaT_trybinassocTM(L, p1, &aux, flip, res, event); 189 | } 190 | 191 | 192 | /* 193 | ** Calls an order tag method. 194 | ** For lessequal, LUA_COMPAT_LT_LE keeps compatibility with old 195 | ** behavior: if there is no '__le', try '__lt', based on l <= r iff 196 | ** !(r < l) (assuming a total order). If the metamethod yields during 197 | ** this substitution, the continuation has to know about it (to negate 198 | ** the result of rtop.p, event)) /* try original event */ 204 | return !l_isfalse(s2v(L->top.p)); 205 | #if defined(LUA_COMPAT_LT_LE) 206 | else if (event == TM_LE) { 207 | /* try '!(p2 < p1)' for '(p1 <= p2)' */ 208 | L->ci->callstatus |= CIST_LEQ; /* mark it is doing 'lt' for 'le' */ 209 | if (callbinTM(L, p2, p1, L->top.p, TM_LT)) { 210 | L->ci->callstatus ^= CIST_LEQ; /* clear mark */ 211 | return l_isfalse(s2v(L->top.p)); 212 | } 213 | /* else error will remove this 'ci'; no need to clear mark */ 214 | } 215 | #endif 216 | luaG_ordererror(L, p1, p2); /* no metamethod found */ 217 | return 0; /* to avoid warnings */ 218 | } 219 | 220 | 221 | int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, 222 | int flip, int isfloat, TMS event) { 223 | TValue aux; const TValue *p2; 224 | if (isfloat) { 225 | setfltvalue(&aux, cast_num(v2)); 226 | } 227 | else 228 | setivalue(&aux, v2); 229 | if (flip) { /* arguments were exchanged? */ 230 | p2 = p1; p1 = &aux; /* correct them */ 231 | } 232 | else 233 | p2 = &aux; 234 | return luaT_callorderTM(L, p1, p2, event); 235 | } 236 | 237 | 238 | void luaT_adjustvarargs (lua_State *L, int nfixparams, CallInfo *ci, 239 | const Proto *p) { 240 | int i; 241 | int actual = cast_int(L->top.p - ci->func.p) - 1; /* number of arguments */ 242 | int nextra = actual - nfixparams; /* number of extra arguments */ 243 | ci->u.l.nextraargs = nextra; 244 | luaD_checkstack(L, p->maxstacksize + 1); 245 | /* copy function to the top of the stack */ 246 | setobjs2s(L, L->top.p++, ci->func.p); 247 | /* move fixed parameters to the top of the stack */ 248 | for (i = 1; i <= nfixparams; i++) { 249 | setobjs2s(L, L->top.p++, ci->func.p + i); 250 | setnilvalue(s2v(ci->func.p + i)); /* erase original parameter (for GC) */ 251 | } 252 | ci->func.p += actual + 1; 253 | ci->top.p += actual + 1; 254 | lua_assert(L->top.p <= ci->top.p && ci->top.p <= L->stack_last.p); 255 | } 256 | 257 | 258 | void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) { 259 | int i; 260 | int nextra = ci->u.l.nextraargs; 261 | if (wanted < 0) { 262 | wanted = nextra; /* get all extra arguments available */ 263 | checkstackGCp(L, nextra, where); /* ensure stack space */ 264 | L->top.p = where + nextra; /* next instruction will need top */ 265 | } 266 | for (i = 0; i < wanted && i < nextra; i++) 267 | setobjs2s(L, where + i, ci->func.p - nextra + i); 268 | for (; i < wanted; i++) /* complete required results with nil */ 269 | setnilvalue(s2v(where + i)); 270 | } 271 | 272 | -------------------------------------------------------------------------------- /lua-5.4.7/src/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_CLOSE, 44 | TM_N /* number of elements in the enum */ 45 | } TMS; 46 | 47 | 48 | /* 49 | ** Mask with 1 in all fast-access methods. A 1 in any of these bits 50 | ** in the flag of a (meta)table means the metatable does not have the 51 | ** corresponding metamethod field. (Bit 7 of the flag is used for 52 | ** 'isrealasize'.) 53 | */ 54 | #define maskflags (~(~0u << (TM_EQ + 1))) 55 | 56 | 57 | /* 58 | ** Test whether there is no tagmethod. 59 | ** (Because tagmethods use raw accesses, the result may be an "empty" nil.) 60 | */ 61 | #define notm(tm) ttisnil(tm) 62 | 63 | 64 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 65 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 66 | 67 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 68 | 69 | #define ttypename(x) luaT_typenames_[(x) + 1] 70 | 71 | LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];) 72 | 73 | 74 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 75 | 76 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 77 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 78 | TMS event); 79 | LUAI_FUNC void luaT_init (lua_State *L); 80 | 81 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 82 | const TValue *p2, const TValue *p3); 83 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, 84 | const TValue *p1, const TValue *p2, StkId p3); 85 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 86 | StkId res, TMS event); 87 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); 88 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, 89 | const TValue *p2, int inv, StkId res, TMS event); 90 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, 91 | int inv, StkId res, TMS event); 92 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 93 | const TValue *p2, TMS event); 94 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, 95 | int inv, int isfloat, TMS event); 96 | 97 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, 98 | struct CallInfo *ci, const Proto *p); 99 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, 100 | StkId where, int wanted); 101 | 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define LUAC_VERSION (((LUA_VERSION_NUM / 100) * 16) + LUA_VERSION_NUM % 100) 25 | 26 | #define LUAC_FORMAT 0 /* this is the official format */ 27 | 28 | /* load one chunk; from lundump.c */ 29 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 30 | 31 | /* dump one chunk; from ldump.c */ 32 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 33 | void* data, int strip); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | /* 31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers 32 | ** by flooring them (instead of raising an error if they are not 33 | ** integral values) 34 | */ 35 | #if !defined(LUA_FLOORN2I) 36 | #define LUA_FLOORN2I F2Ieq 37 | #endif 38 | 39 | 40 | /* 41 | ** Rounding modes for float->integer coercion 42 | */ 43 | typedef enum { 44 | F2Ieq, /* no rounding; accepts only integral values */ 45 | F2Ifloor, /* takes the floor of the number */ 46 | F2Iceil /* takes the ceil of the number */ 47 | } F2Imod; 48 | 49 | 50 | /* convert an object to a float (including string coercion) */ 51 | #define tonumber(o,n) \ 52 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 53 | 54 | 55 | /* convert an object to a float (without string coercion) */ 56 | #define tonumberns(o,n) \ 57 | (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \ 58 | (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0)) 59 | 60 | 61 | /* convert an object to an integer (including string coercion) */ 62 | #define tointeger(o,i) \ 63 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 64 | : luaV_tointeger(o,i,LUA_FLOORN2I)) 65 | 66 | 67 | /* convert an object to an integer (without string coercion) */ 68 | #define tointegerns(o,i) \ 69 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 70 | : luaV_tointegerns(o,i,LUA_FLOORN2I)) 71 | 72 | 73 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 74 | 75 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 76 | 77 | 78 | /* 79 | ** fast track for 'gettable': if 't' is a table and 't[k]' is present, 80 | ** return 1 with 'slot' pointing to 't[k]' (position of final result). 81 | ** Otherwise, return 0 (meaning it will have to check metamethod) 82 | ** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL 83 | ** (otherwise). 'f' is the raw get function to use. 84 | */ 85 | #define luaV_fastget(L,t,k,slot,f) \ 86 | (!ttistable(t) \ 87 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 88 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 89 | !isempty(slot))) /* result not empty? */ 90 | 91 | 92 | /* 93 | ** Special case of 'luaV_fastget' for integers, inlining the fast case 94 | ** of 'luaH_getint'. 95 | */ 96 | #define luaV_fastgeti(L,t,k,slot) \ 97 | (!ttistable(t) \ 98 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 99 | : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \ 100 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ 101 | !isempty(slot))) /* result not empty? */ 102 | 103 | 104 | /* 105 | ** Finish a fast set operation (when fast get succeeds). In that case, 106 | ** 'slot' points to the place to put the value. 107 | */ 108 | #define luaV_finishfastset(L,t,slot,v) \ 109 | { setobj2t(L, cast(TValue *,slot), v); \ 110 | luaC_barrierback(L, gcvalue(t), v); } 111 | 112 | 113 | /* 114 | ** Shift right is the same as shift left with a negative 'y' 115 | */ 116 | #define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y)) 117 | 118 | 119 | 120 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 121 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 122 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 123 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 124 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); 125 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, 126 | F2Imod mode); 127 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); 128 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 129 | StkId val, const TValue *slot); 130 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 131 | TValue *val, const TValue *slot); 132 | LUAI_FUNC void luaV_finishOp (lua_State *L); 133 | LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci); 134 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 135 | LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y); 136 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 137 | LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y); 138 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 139 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /lua-5.4.7/src/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /lua-config-package-tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.1) 2 | project(lua-config-package-test C) 3 | 4 | find_package(Lua REQUIRED CONFIG) 5 | 6 | add_executable(lua-config-package-build-test-using-static-target "./lua-config-package-build-test.c") 7 | target_link_libraries(lua-config-package-build-test-using-static-target Lua::lua_static) 8 | 9 | add_executable(lua-config-package-build-test-using-shared-target "./lua-config-package-build-test.c") 10 | target_link_libraries(lua-config-package-build-test-using-shared-target Lua::lua_shared) 11 | 12 | add_executable(lua-config-package-build-test-using-variables "./lua-config-package-build-test.c") 13 | target_link_libraries(lua-config-package-build-test-using-variables "${LUA_LIBRARIES}") 14 | 15 | add_library(lua-lib-module-compatible-mode UNKNOWN IMPORTED "${LUA_LIBRARY}") 16 | set_target_properties(lua-lib-module-compatible-mode PROPERTIES 17 | INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}" 18 | IMPORTED_LOCATION "${LUA_LIBRARY}") 19 | target_link_libraries(lua-lib-module-compatible-mode INTERFACE "${LUA_LIBRARIES}") 20 | 21 | add_executable(lua-config-package-build-test-using-module-compatible-mode "./lua-config-package-build-test.c") 22 | target_link_libraries(lua-config-package-build-test-using-module-compatible-mode lua-lib-module-compatible-mode) 23 | -------------------------------------------------------------------------------- /lua-config-package-tests/lua-config-package-build-test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | lua_State *l = luaL_newstate(); 8 | double lversion = lua_version(l); 9 | printf("Lua version is %f\n", lversion); 10 | } -------------------------------------------------------------------------------- /orig_sources/lua-5.4.6-tests.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walterschell/Lua/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0/orig_sources/lua-5.4.6-tests.tar.gz -------------------------------------------------------------------------------- /orig_sources/lua-5.4.6.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walterschell/Lua/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0/orig_sources/lua-5.4.6.tar.gz -------------------------------------------------------------------------------- /orig_sources/lua-5.4.7-tests.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walterschell/Lua/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0/orig_sources/lua-5.4.7-tests.tar.gz -------------------------------------------------------------------------------- /orig_sources/lua-5.4.7.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walterschell/Lua/3ed55a56eaa05c9221f40b3c07d0e908eb1067b0/orig_sources/lua-5.4.7.tar.gz --------------------------------------------------------------------------------