diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 7b19b46..b458581 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -12,10 +12,10 @@ A clear and concise description of what the bug is. ## Version and Installation Info -- toml.lua version: -- Operating system: -- Installation method: (Manual compilation or `luarocks install toml`) -- Compilation log, or Luarocks installation log: +- toml.lua version: +- Operating system: +- Installation method: (Manual compilation or `luarocks install toml`) +- Compilation log, or Luarocks installation log: ```shell # Paste installation or compilation log here diff --git a/.github/workflows/buildAndTest-FreeBSD.yml b/.github/workflows/buildAndTest-FreeBSD.yml new file mode 100644 index 0000000..8266ca1 --- /dev/null +++ b/.github/workflows/buildAndTest-FreeBSD.yml @@ -0,0 +1,75 @@ +name: "Build and Test on FreeBSD" +on: + push: + branches: + - "main" + pull_request: + +jobs: + RunTestsOnFreeBSD: + name: "FreeBSD 15" + runs-on: "ubuntu-latest" + strategy: + matrix: + compiler: ["gcc", "clang"] + lua: ["luajit", "lua54", "lua53", "lua52", "lua51"] + steps: + - uses: "actions/checkout@v6" + - name: "Setup FreeBSD VM" + uses: vmactions/freebsd-vm@v1 + id: vm + with: + #usesh: true + prepare: | + pkg update + pkg install -y sudo bash + - name: "Add Dependencies" + shell: freebsd {0} + run: | + bash -xc ' + cd $GITHUB_WORKSPACE + export COMPILER=${{ matrix.compiler }} + source ./scripts/compilerName.sh + sudo pkg install -y cmake git ${{ matrix.lua }} "$C_COMPILER_PACKAGE" + export LUA_BIN_NAME=${{ matrix.lua }} + case ${{ matrix.lua }} in + *lua54*) + bash -x scripts/buildLuaRocks.sh "5.4" + ;; + *lua53*) + bash -x scripts/buildLuaRocks.sh "5.3" + ;; + *lua52*) + bash -x scripts/buildLuaRocks.sh "5.2" + ;; + *lua51*) + bash -x scripts/buildLuaRocks.sh "5.1" + ;; + *luajit*) + bash -x scripts/buildLuaRocks.sh "5.1" + ;; + *) + bash -x scripts/buildLuaRocks.sh + ;; + esac + sudo luarocks + sudo luarocks install luaunit + ' + - name: "Build Project" + shell: freebsd {0} + run: | + bash -xc ' + cd $GITHUB_WORKSPACE + export COMPILER=${{ matrix.compiler }} + source scripts/compilerName.sh + sudo luarocks config "variables.CMAKE_CXX_COMPILER" "$CXX_COMPILER" + sudo luarocks config "variables.CMAKE_C_COMPILER" "$C_COMPILER" + sudo CXX="$CXX_COMPILER" CC="$C_COMPILER" luarocks make + ' + - name: "Test Project" + shell: freebsd {0} + run: | + bash -xc ' + cd $GITHUB_WORKSPACE + ${{ matrix.lua }} tests/tests.lua + ' diff --git a/.github/workflows/buildAndTest-Linux.yml b/.github/workflows/buildAndTest-Linux.yml index 9b04899..d3bc602 100644 --- a/.github/workflows/buildAndTest-Linux.yml +++ b/.github/workflows/buildAndTest-Linux.yml @@ -28,7 +28,7 @@ jobs: source scripts/compilerName.sh sudo apt update sudo apt install -yq ${{ matrix.lua }} "$C_COMPILER_PACKAGE" "$CXX_COMPILER_PACKAGE" - ./scripts/buildLuaRocks.sh + bash scripts/buildLuaRocks.sh sudo luarocks install luaunit - name: "Build Project" run: | diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 640dd1d..3268d65 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -1,15 +1,34 @@ -name: "Run Pre-Commit" - +name: "Run pre-commit" on: push: branches: - "main" - + pull_request: + jobs: PreCommit: + permissions: + contents: "write" runs-on: "macos-latest" steps: - - uses: "actions/checkout@v4" + - uses: "actions/checkout@v6" + with: + ref: ${{ github.head_ref }} - name: "Install Dependencies" run: "brew bundle" - - uses: "LebJe/pre-commit-composite-action@0.0.1" + - name: "Run Pre-Commit" + id: "run-pre-commit" + run: | + EXIT_CODE=0 + pre-commit run --all --color=always --show-diff-on-failure || EXIT_CODE=$? + if [[ $EXIT_CODE -ne 0 ]]; then + echo "SHOULD_COMMIT=true" >> "$GITHUB_OUTPUT" + else + echo "SHOULD_COMMIT=false" >> "$GITHUB_OUTPUT" + fi; + - uses: stefanzweifel/git-auto-commit-action@v7 + if: contains(steps.run-pre-commit.outputs.SHOULD_COMMIT, 'true') + with: + commit_message: "Run pre-commit hooks." + file_pattern: ". :(exclude).github/workflows/*" + \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3dbeba5..f718c99 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,8 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: - - repo: "https://github.com/pre-commit/mirrors-prettier.git" - rev: "v4.0.0-alpha.8" + - repo: "https://github.com/rbubley/mirrors-prettier.git" + rev: "v3.7.4" hooks: - id: "prettier" name: "Format YAML & Markdown" diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a705d..fe19daa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,22 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- The formatting options that were passed as a parameter to `toml.encode`, `toml.encodeToFile`, `toml.toJSON`, and `toml.toYAML` previously had no effect when overriding values. -- Resolved CMake `FetchContent_Populate` warning. +- The formatting options that were passed as a parameter to `toml.encode`, `toml.encodeToFile`, `toml.toJSON`, and `toml.toYAML` previously had no effect when overriding values. +- Resolved CMake `FetchContent_Populate` warning. ### Changed -- Updated to magic_enum v0.9.7. +- Updated to magic_enum v0.9.7. ### Added -- Added tests for encoding options. +- Added tests for encoding options. ## [0.4.0](https://github.com/LebJe/toml.lua/releases/tag/0.4.0) - 2024-01-02 ### Added -- `toml.Int` for formatted integers. +- `toml.Int` for formatted integers. ```lua local formattedIntegers = { @@ -41,39 +41,39 @@ int3 = 0x169F --]] ``` -- `formattedIntsAsUserdata` can be passed to the options table of `toml.decode` (see "Decoding Options" in the README). -- Updated to toml++ v3.4.0. -- Updated to MagicEnum v0.9.5. -- toml.lua compiles with MSVC. +- `formattedIntsAsUserdata` can be passed to the options table of `toml.decode` (see "Decoding Options" in the README). +- Updated to toml++ v3.4.0. +- Updated to MagicEnum v0.9.5. +- toml.lua compiles with MSVC. ## [0.3.0](https://github.com/LebJe/toml.lua/releases/tag/0.3.0) - 2023-02-19 ### Added -- `toml.decodeFromFile(filePath: string)`: - - Decodes a TOML document at `filePath`. Throws the same errors as `toml.decode`. -- `toml.encodeToFile(data: table, fileOrOptions: string|table)`: - - Encodes `data` to the file specified in `fileOrOptions`. the file will be created if it doesn't exist. - - When `fileOrOptions` is a string, it simply is the file path. - - When `fileOrOptions` is a table, it should have`file`, and optionally, `overwrite` as keys. `file` is the file path, and `overwrite` should be `true` when `file` should be overwritten with `data`, and `false` when `data` should be appended to `file`. -- Added tests that cover: - - The property accessors of `toml.Date`, `toml.Time`, `toml.DateTime`, and `toml.TimeOffset`. - - `toml.toJSON` and `toml.toYAML`. +- `toml.decodeFromFile(filePath: string)`: + - Decodes a TOML document at `filePath`. Throws the same errors as `toml.decode`. +- `toml.encodeToFile(data: table, fileOrOptions: string|table)`: + - Encodes `data` to the file specified in `fileOrOptions`. the file will be created if it doesn't exist. + - When `fileOrOptions` is a string, it simply is the file path. + - When `fileOrOptions` is a table, it should have`file`, and optionally, `overwrite` as keys. `file` is the file path, and `overwrite` should be `true` when `file` should be overwritten with `data`, and `false` when `data` should be appended to `file`. +- Added tests that cover: + - The property accessors of `toml.Date`, `toml.Time`, `toml.DateTime`, and `toml.TimeOffset`. + - `toml.toJSON` and `toml.toYAML`. ### Changed -- `toml.tomlToJSON` and `toml.tomlToYAML` have been renamed to `toml.toJSON` and `toml.toYAML`. - - They have been renamed because they now have two functions: converting a TOML string to JSON/YAML (as before), or converting a table into JSON/YAML. - - The first parameter can be a string containing TOML (as before), or a table. +- `toml.tomlToJSON` and `toml.tomlToYAML` have been renamed to `toml.toJSON` and `toml.toYAML`. + - They have been renamed because they now have two functions: converting a TOML string to JSON/YAML (as before), or converting a table into JSON/YAML. + - The first parameter can be a string containing TOML (as before), or a table. ## [0.2.0](https://github.com/LebJe/toml.lua/releases/tag/0.2.0) - 2023-02-12 ### Added -- Updated to toml++ v3.3.0 -- Added `terseKeyValuePairs` to the list of formatting options for `toml.encode` -- Tables can be made inline. -- `toml.decode` can decode date, time and date-time into userdata (as before) or plain tables: +- Updated to toml++ v3.3.0 +- Added `terseKeyValuePairs` to the list of formatting options for `toml.encode` +- Tables can be made inline. +- `toml.decode` can decode date, time and date-time into userdata (as before) or plain tables: ```lua local tomlStr = [[ @@ -126,63 +126,63 @@ int3 = 0x169F --]] ``` -- Test suite now runs on Windows +- Test suite now runs on Windows ### Changed -- Use [luaunit](https://github.com/bluebird75/luaunit) instead of [busted](https://github.com/lunarmodules/busted) for testing -- `quoteDatesAndTimes` now defaults to `false`. +- Use [luaunit](https://github.com/bluebird75/luaunit) instead of [busted](https://github.com/lunarmodules/busted) for testing +- `quoteDatesAndTimes` now defaults to `false`. ### Fixed -- Boolean values are decoded as booleans instead of integers. (#6) +- Boolean values are decoded as booleans instead of integers. (#6) ## [0.1.1](https://github.com/LebJe/toml.lua/releases/tag/0.1.1) - 2022-06-14 ### Added -- Windows support. +- Windows support. ## [0.1.0](https://github.com/LebJe/toml.lua/releases/tag/0.1.0) - 2022-04-08 ### Added -- Upgrade to [toml++ 3.0.1](https://github.com/marzer/tomlplusplus/releases/tag/v3.0.1) -- TOML documents can be converted to JSON or YAML. -- Formatting options can be passed to the `encode`, `tomlToJSON`, and `tomlToYAML` functions. +- Upgrade to [toml++ 3.0.1](https://github.com/marzer/tomlplusplus/releases/tag/v3.0.1) +- TOML documents can be converted to JSON or YAML. +- Formatting options can be passed to the `encode`, `tomlToJSON`, and `tomlToYAML` functions. ### Removed -- Removed `formattedReason` from decoding error messages. +- Removed `formattedReason` from decoding error messages. ## [0.0.4](https://github.com/LebJe/toml.lua/releases/tag/0.0.4) - 2021-11-24 ### Added -- toml.lua is now tested with `g++` and `clang++` with Lua 5.3, 5.2, 5.1 and LuaJIT. +- toml.lua is now tested with `g++` and `clang++` with Lua 5.3, 5.2, 5.1 and LuaJIT. ### Changed -- toml.lua now depends on Lua 5.1, instead of Lua 5.3. +- toml.lua now depends on Lua 5.1, instead of Lua 5.3. ## [0.0.3](https://github.com/LebJe/toml.lua/releases/tag/0.0.3) - 2021-11-08 ### Added -- Date, time, and date-time types. +- Date, time, and date-time types. ### Fixed -- Integers are now inserted into TOML documents as integers, not floating-point numbers. +- Integers are now inserted into TOML documents as integers, not floating-point numbers. ## [0.0.2](https://github.com/LebJe/toml.lua/releases/tag/0.0.2) - 2021-10-29 ### Added -- The `decode` and `tomlToJSON` functions now return a table containing error details instead of a string if parsing a TOML document fails. +- The `decode` and `tomlToJSON` functions now return a table containing error details instead of a string if parsing a TOML document fails. ## [0.0.1](https://github.com/LebJe/toml.lua/releases/tag/0.0.1) - 2021-10-27 ### Added -- Initial Release. +- Initial Release. diff --git a/README.md b/README.md index 313401c..b918452 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Build and Test on MacOS](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-MacOS.yml/badge.svg)](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-MacOS.yml) [![Build and Test on Linux](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-Linux.yml/badge.svg)](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-Linux.yml) +[![Build and Test on FreeBSD](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-FreeBSD.yml/badge.svg)](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-FreeBSD.yml) [![Build and Test on Windows](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-Windows.yml/badge.svg)](https://github.com/LebJe/toml.lua/actions/workflows/buildAndTest-Windows.yml) [![LuaRocks](https://img.shields.io/luarocks/v/LebJe/toml?color=blue&label=LuaRocks&logo=Lua)](https://luarocks.org/modules/LebJe/toml) @@ -13,39 +14,39 @@ toml.lua is a [Lua](https://www.lua.org) wrapper around [toml++](https://github. -- [toml.lua](#tomllua) - - [Table of Contents](#table-of-contents) - - [Installation](#installation) - - [Requirements](#requirements) - - [LuaRocks](#luarocks) - - [MacOS and Linux](#macos-and-linux) - - [Windows](#windows) - - [LLVM](#llvm) - - [MinGW](#mingw) - - [Manual Compilation](#manual-compilation) - - [MacOS and Linux](#macos-and-linux-1) - - [Windows](#windows-1) - - [Build with MinGW](#build-with-mingw) - - [Build with LLVM](#build-with-llvm) - - [Install LuaJIT](#install-luajit) - - [Usage](#usage) - - [Decoding](#decoding) - - [Decoding Options](#decoding-options) - - [temporalTypesAsUserData](#temporaltypesasuserdata) - - [formattedIntsAsUserData](#formattedintsasuserdata) - - [Encoding](#encoding) - - [Error Handling](#error-handling) - - [Inline Tables](#inline-tables) - - [TOML Conversion](#toml-conversion) - - [JSON](#json) - - [YAML](#yaml) - - [Output Formatting](#output-formatting) - - [Formatting Integers](#formatting-integers) - - [Formatting TOML, JSON, or YAML](#formatting-toml-json-or-yaml) - - [Date and Time](#date-and-time) - - [Dependencies](#dependencies) - - [Licenses](#licenses) - - [Contributing](#contributing) +- [toml.lua](#tomllua) + - [Table of Contents](#table-of-contents) + - [Installation](#installation) + - [Requirements](#requirements) + - [LuaRocks](#luarocks) + - [MacOS and Linux](#macos-and-linux) + - [Windows](#windows) + - [LLVM](#llvm) + - [MinGW](#mingw) + - [Manual Compilation](#manual-compilation) + - [MacOS and Linux](#macos-and-linux-1) + - [Windows](#windows-1) + - [Build with MinGW](#build-with-mingw) + - [Build with LLVM](#build-with-llvm) + - [Install LuaJIT](#install-luajit) + - [Usage](#usage) + - [Decoding](#decoding) + - [Decoding Options](#decoding-options) + - [temporalTypesAsUserData](#temporaltypesasuserdata) + - [formattedIntsAsUserData](#formattedintsasuserdata) + - [Encoding](#encoding) + - [Error Handling](#error-handling) + - [Inline Tables](#inline-tables) + - [TOML Conversion](#toml-conversion) + - [JSON](#json) + - [YAML](#yaml) + - [Output Formatting](#output-formatting) + - [Formatting Integers](#formatting-integers) + - [Formatting TOML, JSON, or YAML](#formatting-toml-json-or-yaml) + - [Date and Time](#date-and-time) + - [Dependencies](#dependencies) + - [Licenses](#licenses) + - [Contributing](#contributing) @@ -58,11 +59,11 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc) ### Requirements -- A C++ 17 compiler (Clang, GCC, MinGW) -- [CMake](https://cmake.org) -- Lua C headers (`lua.h`, `lualib.h`, and `lauxlib.h`) -- Lua library (e.g. `liblua51.`) -- Lua >= 5.1 or LuaJIT +- A C++ 17 compiler (Clang, GCC, MinGW) +- [CMake](https://cmake.org) +- Lua C headers (`lua.h`, `lualib.h`, and `lauxlib.h`) +- Lua library (e.g. `liblua51.`) +- Lua >= 5.1 or LuaJIT ### LuaRocks @@ -204,16 +205,16 @@ end ##### `temporalTypesAsUserData` -- `temporalTypesAsUserData = true`: The userdata types `toml.Date`, `toml.Time`, and `toml.DateTime` are used to represent TOML date and time types. +- `temporalTypesAsUserData = true`: The userdata types `toml.Date`, `toml.Time`, and `toml.DateTime` are used to represent TOML date and time types. -- `temporalTypesAsUserData = false`: Lua tables are used to represent TOML date and time types. +- `temporalTypesAsUserData = false`: Lua tables are used to represent TOML date and time types. > The default value is `true` ##### `formattedIntsAsUserData` -- `formattedIntsAsUserData = true`: The userdata type `toml.Int` is used to represent integers in octal, binary, or hexadecimal format. -- `formattedIntsAsUserData = false`: Integers in octal, binary, or hexadecimal format will be represented in decimal. +- `formattedIntsAsUserData = true`: The userdata type `toml.Int` is used to represent integers in octal, binary, or hexadecimal format. +- `formattedIntsAsUserData = false`: Integers in octal, binary, or hexadecimal format will be represented in decimal. > The default value is `false` @@ -581,9 +582,9 @@ Passing an empty table removes all options, while not providing a table will use ## Dependencies -- [toml++](https://github.com/marzer/tomlplusplus/) -- [sol2](https://github.com/ThePhD/sol2) -- [magic_enum](https://github.com/Neargye/magic_enum) +- [toml++](https://github.com/marzer/tomlplusplus/) +- [sol2](https://github.com/ThePhD/sol2) +- [magic_enum](https://github.com/Neargye/magic_enum) ## Licenses diff --git a/scripts/buildLuaRocks.sh b/scripts/buildLuaRocks.sh index 70d4573..d8ae004 100755 --- a/scripts/buildLuaRocks.sh +++ b/scripts/buildLuaRocks.sh @@ -1,11 +1,37 @@ -#!/bin/bash +# First argument is the Lua version Luarocks should use: 5.4, 5.3, 5.2, 5.1 + +case $(uname -v) in + *FreeBSD*) + sudo pkg install -y unzip wget gmake readline curl + ;; + *) + sudo apt install build-essential libreadline-dev unzip wget make -yq + ;; + esac -sudo apt install build-essential libreadline-dev unzip wget make -yq wget "https://luarocks.org/releases/luarocks-3.12.2.tar.gz" tar -zxpf luarocks-3.12.2.tar.gz rm luarocks-3.12.2.tar.gz cd luarocks-3.12.2 -./configure + +case $1 in + *5.4*) + ./configure --lua-version="5.4" + ;; + *5.3*) + ./configure --lua-version="5.3" + ;; + *5.2*) + ./configure --lua-version="5.2" + ;; + *5.1*) + ./configure --lua-version="5.1" + ;; + *) + ./configure + ;; +esac + make sudo make install - mkdir ~/.luarocks +mkdir ~/.luarocks diff --git a/scripts/compilerName.sh b/scripts/compilerName.sh index 7b65431..e3206c5 100755 --- a/scripts/compilerName.sh +++ b/scripts/compilerName.sh @@ -5,12 +5,29 @@ export CXX_COMPILER="" if [[ $COMPILER = "gcc" ]]; then export C_COMPILER_PACKAGE="gcc" - export CXX_COMPILER_PACKAGE="g++" - export C_COMPILER="/usr/bin/gcc" - export CXX_COMPILER="/usr/bin/g++" + case $(uname -v) in + *FreeBSD*) + export CXX_COMPILER_PACKAGE="" + ;; + *) + export CXX_COMPILER_PACKAGE="g++" + ;; + esac + + export C_COMPILER="$(which gcc)" + export CXX_COMPILER="$(which g++)" elif [[ $COMPILER = "clang" ]]; then - export C_COMPILER_PACKAGE="clang" - export CXX_COMPILER_PACKAGE="" - export C_COMPILER="/usr/bin/clang" - export CXX_COMPILER="/usr/bin/clang++" + case $(uname -v) in + *FreeBSD*) + export C_COMPILER_PACKAGE="llvm" + export CXX_COMPILER_PACKAGE="" + ;; + *) + export C_COMPILER_PACKAGE="clang" + export CXX_COMPILER_PACKAGE="" + ;; + esac + + export C_COMPILER="$(which clang)" + export CXX_COMPILER="$(which clang++)" fi diff --git a/src/toml.cpp b/src/toml.cpp index 7d1678e..157b744 100644 --- a/src/toml.cpp +++ b/src/toml.cpp @@ -33,8 +33,9 @@ template inline int tomlTo(sol::state_view state, toml::format_flags f return luaL_argerror( L, 1, std::string( - std::string("A string containing a TOML document, or a table with strings as keys " - "should be the first argument, not") + + std::string( + "A string containing a TOML document, or a table with strings as keys " + "should be the first argument, not") + solLuaDataTypeToString(sol::type_of(L, 1))) .c_str()); } @@ -103,8 +104,9 @@ extern "C" { return luaL_argerror( L, 2, std::string( - std::string("A file path (string), or a table should be the second " - "argument, not ") + + std::string( + "A file path (string), or a table should be the second " + "argument, not ") + solLuaDataTypeToString(sol::type_of(L, 2))) .c_str()); }