diff --git a/.gitattributes b/.gitattributes index 3efb273..3cb3e3e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,5 @@ * text=auto -# Temporarily highlight luau as normal lua files -# until we get native linguist support for Luau -*.luau linguist-language=Lua - # Ensure all lua files use LF *.lua eol=lf *.luau eol=lf diff --git a/CHANGELOG.md b/CHANGELOG.md index 083569f..6aedd71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## `0.8.6` - June 23rd, 2024 ### Added -- Added a builtin API for hashing and calculating HMACs as part of the `serde` library +- Added a builtin API for hashing and calculating HMACs as part of the `serde` library ([#193]) Basic usage: @@ -36,6 +36,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 By default, globals are injected and codegen is disabled. Check the documentation for the `luau` standard library for more information. +- Implemented support for floor division operator / `__idiv` for the `Vector2` and `Vector3` types in the `roblox` standard library ([#196]) +- Fixed the `_VERSION` global containing an incorrect Lune version string. + ### Changed - Sandboxing and codegen in the Luau VM is now fully enabled, resulting in up to 2x or faster code execution. @@ -46,6 +49,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed `__type` and `__tostring` metamethods on userdatas and tables not being respected when printed or formatted using `stdio.format`. +[#193]: https://github.com/lune-org/lune/pull/193 +[#196]: https://github.com/lune-org/lune/pull/196 + ## `0.8.5` - June 1st, 2024 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 434f2e6..956c33c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -305,9 +305,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.5.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" +checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" dependencies = [ "arrayref", "arrayvec 0.7.4", @@ -1504,7 +1504,7 @@ dependencies = [ [[package]] name = "lune" -version = "0.8.5" +version = "0.8.6" dependencies = [ "anyhow", "clap", @@ -1533,7 +1533,7 @@ dependencies = [ [[package]] name = "lune-roblox" -version = "0.1.1" +version = "0.1.2" dependencies = [ "glam", "lune-utils", @@ -1550,7 +1550,7 @@ dependencies = [ [[package]] name = "lune-std" -version = "0.1.2" +version = "0.1.3" dependencies = [ "lune-std-datetime", "lune-std-fs", @@ -1572,7 +1572,7 @@ dependencies = [ [[package]] name = "lune-std-datetime" -version = "0.1.1" +version = "0.1.2" dependencies = [ "chrono", "chrono_lc", @@ -1583,7 +1583,7 @@ dependencies = [ [[package]] name = "lune-std-fs" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bstr", "lune-std-datetime", @@ -1594,7 +1594,7 @@ dependencies = [ [[package]] name = "lune-std-luau" -version = "0.1.0" +version = "0.1.1" dependencies = [ "lune-utils", "mlua", @@ -1602,7 +1602,7 @@ dependencies = [ [[package]] name = "lune-std-net" -version = "0.1.0" +version = "0.1.1" dependencies = [ "bstr", "futures-util", @@ -1623,7 +1623,7 @@ dependencies = [ [[package]] name = "lune-std-process" -version = "0.1.1" +version = "0.1.2" dependencies = [ "bstr", "bytes", @@ -1638,7 +1638,7 @@ dependencies = [ [[package]] name = "lune-std-regex" -version = "0.1.0" +version = "0.1.1" dependencies = [ "lune-utils", "mlua", @@ -1648,7 +1648,7 @@ dependencies = [ [[package]] name = "lune-std-roblox" -version = "0.1.1" +version = "0.1.2" dependencies = [ "lune-roblox", "lune-utils", @@ -1660,7 +1660,7 @@ dependencies = [ [[package]] name = "lune-std-serde" -version = "0.1.0" +version = "0.1.1" dependencies = [ "async-compression", "blake3", @@ -1683,7 +1683,7 @@ dependencies = [ [[package]] name = "lune-std-stdio" -version = "0.1.0" +version = "0.1.1" dependencies = [ "dialoguer", "lune-utils", @@ -1694,7 +1694,7 @@ dependencies = [ [[package]] name = "lune-std-task" -version = "0.1.0" +version = "0.1.1" dependencies = [ "lune-utils", "mlua", @@ -1704,7 +1704,7 @@ dependencies = [ [[package]] name = "lune-utils" -version = "0.1.1" +version = "0.1.2" dependencies = [ "console", "dunce", diff --git a/README.md b/README.md index 34e03e2..f1f10dc 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Lune provides fully asynchronous APIs wherever possible, and is built in Rust ## Features - 🌙 Strictly minimal but powerful interface that is easy to read and remember, just like Luau itself -- 🧰 Fully featured APIs for the filesystem, networking, stdio, all included in the small (~5mb) executable +- 🧰 Fully featured APIs for the filesystem, networking, stdio, all included in the small (~5mb zipped) executable - 📚 World-class documentation, on the web _or_ directly in your editor, no network connection necessary - 🏡 Familiar runtime environment for Roblox developers, with an included 1-to-1 task scheduler port - ✏️ Optional built-in library for manipulating Roblox place & model files, and their instances diff --git a/crates/lune-roblox/Cargo.toml b/crates/lune-roblox/Cargo.toml index a122b68..f1e66c5 100644 --- a/crates/lune-roblox/Cargo.toml +++ b/crates/lune-roblox/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-roblox" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -26,4 +26,4 @@ rbx_reflection = "4.4.0" rbx_reflection_database = "0.2.9" rbx_xml = "0.13.2" -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std-datetime/Cargo.toml b/crates/lune-std-datetime/Cargo.toml index efa5d32..2cef92e 100644 --- a/crates/lune-std-datetime/Cargo.toml +++ b/crates/lune-std-datetime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-datetime" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -19,4 +19,4 @@ thiserror = "1.0" chrono = "0.4.38" chrono_lc = "0.1.6" -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std-fs/Cargo.toml b/crates/lune-std-fs/Cargo.toml index 033e60d..144e5f2 100644 --- a/crates/lune-std-fs/Cargo.toml +++ b/crates/lune-std-fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-fs" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -19,5 +19,5 @@ bstr = "1.9" tokio = { version = "1", default-features = false, features = ["fs"] } -lune-utils = { version = "0.1.0", path = "../lune-utils" } -lune-std-datetime = { version = "0.1.0", path = "../lune-std-datetime" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } +lune-std-datetime = { version = "0.1.1", path = "../lune-std-datetime" } diff --git a/crates/lune-std-luau/Cargo.toml b/crates/lune-std-luau/Cargo.toml index a4d1b23..e94511f 100644 --- a/crates/lune-std-luau/Cargo.toml +++ b/crates/lune-std-luau/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-luau" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -13,6 +13,6 @@ path = "src/lib.rs" workspace = true [dependencies] -mlua = { version = "0.9.7", features = ["luau"] } +mlua = { version = "0.9.7", features = ["luau", "luau-jit"] } -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std-net/Cargo.toml b/crates/lune-std-net/Cargo.toml index fa25858..ef4722e 100644 --- a/crates/lune-std-net/Cargo.toml +++ b/crates/lune-std-net/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-net" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -35,5 +35,5 @@ tokio = { version = "1", default-features = false, features = [ "macros", ] } -lune-utils = { version = "0.1.0", path = "../lune-utils" } -lune-std-serde = { version = "0.1.0", path = "../lune-std-serde" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } +lune-std-serde = { version = "0.1.1", path = "../lune-std-serde" } diff --git a/crates/lune-std-process/Cargo.toml b/crates/lune-std-process/Cargo.toml index 5b19e03..684d776 100644 --- a/crates/lune-std-process/Cargo.toml +++ b/crates/lune-std-process/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-process" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -31,4 +31,4 @@ tokio = { version = "1", default-features = false, features = [ "sync", ] } -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std-regex/Cargo.toml b/crates/lune-std-regex/Cargo.toml index 5bebcb5..c64b08e 100644 --- a/crates/lune-std-regex/Cargo.toml +++ b/crates/lune-std-regex/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-regex" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -18,4 +18,4 @@ mlua = { version = "0.9.7", features = ["luau"] } regex = "1.10" self_cell = "1.0" -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std-roblox/Cargo.toml b/crates/lune-std-roblox/Cargo.toml index a2cc387..964e80c 100644 --- a/crates/lune-std-roblox/Cargo.toml +++ b/crates/lune-std-roblox/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-roblox" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -19,5 +19,5 @@ mlua-luau-scheduler = { version = "0.0.2", path = "../mlua-luau-scheduler" } once_cell = "1.17" rbx_cookie = { version = "0.1.4", default-features = false } -lune-utils = { version = "0.1.0", path = "../lune-utils" } -lune-roblox = { version = "0.1.1", path = "../lune-roblox" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } +lune-roblox = { version = "0.1.2", path = "../lune-roblox" } diff --git a/crates/lune-std-serde/Cargo.toml b/crates/lune-std-serde/Cargo.toml index ab7bec0..98a8f44 100644 --- a/crates/lune-std-serde/Cargo.toml +++ b/crates/lune-std-serde/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-serde" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -37,11 +37,11 @@ sha2 = "0.10.8" sha3 = "0.10.8" # This feature MIGHT break due to the unstable nature of the digest crate. # Check before updating it. -blake3 = { version = "1.5.0", features = ["traits-preview"] } +blake3 = { version = "=1.5.0", features = ["traits-preview"] } tokio = { version = "1", default-features = false, features = [ "rt", "io-util", ] } -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std-serde/src/hash.rs b/crates/lune-std-serde/src/hash.rs index cf0d3c6..251976e 100644 --- a/crates/lune-std-serde/src/hash.rs +++ b/crates/lune-std-serde/src/hash.rs @@ -35,12 +35,34 @@ enum HashAlgorithm { } impl HashAlgorithm { - pub fn list_all_as_string() -> String { - [ - "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "sha3-224", "sha3-256", - "sha3-384", "sha3-512", "blake3", - ] - .join(", ") + pub const ALL: [Self; 11] = [ + Self::Md5, + Self::Sha1, + Self::Sha2_224, + Self::Sha2_256, + Self::Sha2_384, + Self::Sha2_512, + Self::Sha3_224, + Self::Sha3_256, + Self::Sha3_384, + Self::Sha3_512, + Self::Blake3, + ]; + + pub const fn name(self) -> &'static str { + match self { + Self::Md5 => "md5", + Self::Sha1 => "sha1", + Self::Sha2_224 => "sha224", + Self::Sha2_256 => "sha256", + Self::Sha2_384 => "sha384", + Self::Sha2_512 => "sha512", + Self::Sha3_224 => "sha3-224", + Self::Sha3_256 => "sha3-256", + Self::Sha3_384 => "sha3-384", + Self::Sha3_512 => "sha3-512", + Self::Blake3 => "blake3", + } } } @@ -164,15 +186,15 @@ impl<'lua> FromLua<'lua> for HashAlgorithm { "md5" => Ok(Self::Md5), "sha1" => Ok(Self::Sha1), - "sha224" => Ok(Self::Sha2_224), - "sha256" => Ok(Self::Sha2_256), - "sha384" => Ok(Self::Sha2_384), - "sha512" => Ok(Self::Sha2_512), + "sha2-224" | "sha2_224" | "sha224" => Ok(Self::Sha2_224), + "sha2-256" | "sha2_256" | "sha256" => Ok(Self::Sha2_256), + "sha2-384" | "sha2_384" | "sha384" => Ok(Self::Sha2_384), + "sha2-512" | "sha2_512" | "sha512" => Ok(Self::Sha2_512), - "sha3-224" => Ok(Self::Sha3_224), - "sha3-256" => Ok(Self::Sha3_256), - "sha3-384" => Ok(Self::Sha3_384), - "sha3-512" => Ok(Self::Sha3_512), + "sha3-224" | "sha3_224" => Ok(Self::Sha3_224), + "sha3-256" | "sha3_256" => Ok(Self::Sha3_256), + "sha3-384" | "sha3_384" => Ok(Self::Sha3_384), + "sha3-512" | "sha3_512" => Ok(Self::Sha3_512), "blake3" => Ok(Self::Blake3), @@ -181,7 +203,11 @@ impl<'lua> FromLua<'lua> for HashAlgorithm { to: "HashAlgorithm", message: Some(format!( "Invalid hashing algorithm '{str}', valid kinds are:\n{}", - HashAlgorithm::list_all_as_string() + HashAlgorithm::ALL + .into_iter() + .map(HashAlgorithm::name) + .collect::>() + .join(", ") )), }), } diff --git a/crates/lune-std-stdio/Cargo.toml b/crates/lune-std-stdio/Cargo.toml index 2e26e98..9e8cdf2 100644 --- a/crates/lune-std-stdio/Cargo.toml +++ b/crates/lune-std-stdio/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-stdio" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -22,4 +22,4 @@ tokio = { version = "1", default-features = false, features = [ "io-util", ] } -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std-task/Cargo.toml b/crates/lune-std-task/Cargo.toml index b18fc7b..05ef45c 100644 --- a/crates/lune-std-task/Cargo.toml +++ b/crates/lune-std-task/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std-task" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -18,4 +18,4 @@ mlua-luau-scheduler = { version = "0.0.2", path = "../mlua-luau-scheduler" } tokio = { version = "1", default-features = false, features = ["time"] } -lune-utils = { version = "0.1.0", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } diff --git a/crates/lune-std/Cargo.toml b/crates/lune-std/Cargo.toml index 83ccab7..da06494 100644 --- a/crates/lune-std/Cargo.toml +++ b/crates/lune-std/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std" -version = "0.1.2" +version = "0.1.3" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -45,15 +45,15 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" tokio = { version = "1", default-features = false, features = ["fs", "sync"] } -lune-utils = { version = "0.1.1", path = "../lune-utils" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } -lune-std-datetime = { optional = true, version = "0.1.1", path = "../lune-std-datetime" } -lune-std-fs = { optional = true, version = "0.1.0", path = "../lune-std-fs" } -lune-std-luau = { optional = true, version = "0.1.0", path = "../lune-std-luau" } -lune-std-net = { optional = true, version = "0.1.0", path = "../lune-std-net" } -lune-std-process = { optional = true, version = "0.1.1", path = "../lune-std-process" } -lune-std-regex = { optional = true, version = "0.1.0", path = "../lune-std-regex" } -lune-std-roblox = { optional = true, version = "0.1.1", path = "../lune-std-roblox" } -lune-std-serde = { optional = true, version = "0.1.0", path = "../lune-std-serde" } -lune-std-stdio = { optional = true, version = "0.1.0", path = "../lune-std-stdio" } -lune-std-task = { optional = true, version = "0.1.0", path = "../lune-std-task" } +lune-std-datetime = { optional = true, version = "0.1.2", path = "../lune-std-datetime" } +lune-std-fs = { optional = true, version = "0.1.1", path = "../lune-std-fs" } +lune-std-luau = { optional = true, version = "0.1.1", path = "../lune-std-luau" } +lune-std-net = { optional = true, version = "0.1.1", path = "../lune-std-net" } +lune-std-process = { optional = true, version = "0.1.2", path = "../lune-std-process" } +lune-std-regex = { optional = true, version = "0.1.1", path = "../lune-std-regex" } +lune-std-roblox = { optional = true, version = "0.1.2", path = "../lune-std-roblox" } +lune-std-serde = { optional = true, version = "0.1.1", path = "../lune-std-serde" } +lune-std-stdio = { optional = true, version = "0.1.1", path = "../lune-std-stdio" } +lune-std-task = { optional = true, version = "0.1.1", path = "../lune-std-task" } diff --git a/crates/lune-utils/Cargo.toml b/crates/lune-utils/Cargo.toml index 29658d0..7390b70 100644 --- a/crates/lune-utils/Cargo.toml +++ b/crates/lune-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-utils" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" diff --git a/crates/lune/Cargo.toml b/crates/lune/Cargo.toml index ea5dac7..013b554 100644 --- a/crates/lune/Cargo.toml +++ b/crates/lune/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune" -version = "0.8.5" +version = "0.8.6" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -71,9 +71,9 @@ reqwest = { version = "0.11", default-features = false, features = [ "rustls-tls", ] } -lune-std = { optional = true, version = "0.1.2", path = "../lune-std" } -lune-roblox = { optional = true, version = "0.1.1", path = "../lune-roblox" } -lune-utils = { version = "0.1.1", path = "../lune-utils" } +lune-std = { optional = true, version = "0.1.3", path = "../lune-std" } +lune-roblox = { optional = true, version = "0.1.2", path = "../lune-roblox" } +lune-utils = { version = "0.1.2", path = "../lune-utils" } ### CLI diff --git a/crates/lune/src/rt/runtime.rs b/crates/lune/src/rt/runtime.rs index 08a601c..1aa2ace 100644 --- a/crates/lune/src/rt/runtime.rs +++ b/crates/lune/src/rt/runtime.rs @@ -57,6 +57,7 @@ impl RuntimeInner { feature = "std-task", ))] { + lune_std::set_global_version(lua, env!("CARGO_PKG_VERSION")); lune_std::inject_globals(lua)?; } diff --git a/types/regex.luau b/types/regex.luau index e148c73..59756f3 100644 --- a/types/regex.luau +++ b/types/regex.luau @@ -180,7 +180,7 @@ export type Regex = typeof(Regex) ### Example usage ```lua - local Regex = require("@lune/regex") + local Regex = require("@lune/regex") local re = Regex.new("hello") diff --git a/types/serde.luau b/types/serde.luau index ff12714..aa17edc 100644 --- a/types/serde.luau +++ b/types/serde.luau @@ -1,7 +1,58 @@ +--[=[ + @within Serde + @interface EncodeDecodeFormat + + A serialization/deserialization format supported by the Serde library. + + Currently supported formats: + + | Name | Learn More | + |:-------|:---------------------| + | `json` | https://www.json.org | + | `yaml` | https://yaml.org | + | `toml` | https://toml.io | +]=] export type EncodeDecodeFormat = "json" | "yaml" | "toml" +--[=[ + @within Serde + @interface CompressDecompressFormat + + A compression/decompression format supported by the Serde library. + + Currently supported formats: + + | Name | Learn More | + |:---------|:----------------------------------| + | `brotli` | https://github.com/google/brotli | + | `gzip` | https://www.gnu.org/software/gzip | + | `lz4` | https://github.com/lz4/lz4 | + | `zlib` | https://www.zlib.net | +]=] export type CompressDecompressFormat = "brotli" | "gzip" | "lz4" | "zlib" +--[=[ + @within Serde + @interface HashAlgorithm + + A hash algorithm supported by the Serde library. + + Currently supported algorithms: + + | Name | Learn More | + |:-----------|:-------------------------------------| + | `md5` | https://en.wikipedia.org/wiki/MD5 | + | `sha1` | https://en.wikipedia.org/wiki/SHA-1 | + | `sha224` | https://en.wikipedia.org/wiki/SHA-2 | + | `sha256` | https://en.wikipedia.org/wiki/SHA-2 | + | `sha384` | https://en.wikipedia.org/wiki/SHA-2 | + | `sha512` | https://en.wikipedia.org/wiki/SHA-2 | + | `sha3-224` | https://en.wikipedia.org/wiki/SHA-3 | + | `sha3-256` | https://en.wikipedia.org/wiki/SHA-3 | + | `sha3-384` | https://en.wikipedia.org/wiki/SHA-3 | + | `sha3-512` | https://en.wikipedia.org/wiki/SHA-3 | + | `blake3` | https://en.wikipedia.org/wiki/BLAKE3 | +]=] export type HashAlgorithm = "md5" | "sha1" @@ -48,13 +99,7 @@ local serde = {} Encodes the given value using the given format. - Currently supported formats: - - | Name | Learn More | - |:-------|:---------------------| - | `json` | https://www.json.org | - | `yaml` | https://yaml.org | - | `toml` | https://toml.io | + See [`EncodeDecodeFormat`] for a list of supported formats. @param format The format to use @param value The value to encode @@ -71,13 +116,7 @@ end Decodes the given string using the given format into a lua value. - Currently supported formats: - - | Name | Learn More | - |:-------|:---------------------| - | `json` | https://www.json.org | - | `yaml` | https://yaml.org | - | `toml` | https://toml.io | + See [`EncodeDecodeFormat`] for a list of supported formats. @param format The format to use @param encoded The string to decode @@ -93,14 +132,7 @@ end Compresses the given string using the given format. - Currently supported formats: - - | Name | Learn More | - |:---------|:----------------------------------| - | `brotli` | https://github.com/google/brotli | - | `gzip` | https://www.gnu.org/software/gzip | - | `lz4` | https://github.com/lz4/lz4 | - | `zlib` | https://www.zlib.net | + See [`CompressDecompressFormat`] for a list of supported formats. @param format The format to use @param s The string to compress @@ -116,14 +148,7 @@ end Decompresses the given string using the given format. - Currently supported formats: - - | Name | Learn More | - |:---------|:----------------------------------| - | `brotli` | https://github.com/google/brotli | - | `gzip` | https://www.gnu.org/software/gzip | - | `lz4` | https://github.com/lz4/lz4 | - | `zlib` | https://www.zlib.net | + See [`CompressDecompressFormat`] for a list of supported formats. @param format The format to use @param s The string to decompress @@ -133,10 +158,36 @@ function serde.decompress(format: CompressDecompressFormat, s: buffer | string): return nil :: any end +--[=[ + @within Serde + @tag must_use + + Hashes the given message using the given algorithm + and returns the hash as a hex string. + + See [`HashAlgorithm`] for a list of supported algorithms. + + @param algorithm The algorithm to use + @param message The message to hash + @return The hash as a hex string +]=] function serde.hash(algorithm: HashAlgorithm, message: string | buffer): string return nil :: any end +--[=[ + @within Serde + @tag must_use + + Hashes the given message using HMAC with the given secret + and algorithm, returning the hash as a base64 string. + + See [`HashAlgorithm`] for a list of supported algorithms. + + @param algorithm The algorithm to use + @param message The message to hash + @return The hash as a base64 string +]=] function serde.hmac( algorithm: HashAlgorithm, message: string | buffer,