diff --git a/CHANGELOG.md b/CHANGELOG.md index be64496..fb04ac7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## `0.8.4` - May 12th, 2024 -### Changed +### Added - Added a builtin API for regular expressions. @@ -51,6 +51,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Currently supported targets are the same as the ones included with each release of Lune on GitHub. Check releases for a full list of targets. +- Added `stdio.readToEnd()` for reading the entire stdin passed to Lune + +### Changed + - Split the repository into modular crates instead of a monolith. ([#188]) If you previously depended on Lune as a crate, nothing about it has changed for version `0.8.4`, but now each individual sub-crate has also been published and is available for use: @@ -64,7 +68,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 In general, this should mean that it is now much easier to make your own Lune builtin, publish your own flavor of a Lune CLI, or take advantage of all the work that has been done for Lune as a runtime when making your own Rust programs. -- Added `stdio.readToEnd()` for reading the entire stdin passed to Lune - Changed the `User-Agent` header in `net.request` to be more descriptive ([#186]) - Updated to Luau version `0.622`. diff --git a/Cargo.lock b/Cargo.lock index fdfa079..cfbf36f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -412,9 +412,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", @@ -426,9 +426,9 @@ dependencies = [ [[package]] name = "chrono_lc" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809c968b91b4949802fba00279fd0610158cbb2ae5f10663f0c3d5331f88d6d6" +checksum = "aa1812634894df89eb9d5075eba0b97d42b4affe477bde7d0db3d2cf8454a800" dependencies = [ "chrono", "lazy_static", @@ -779,29 +779,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" -[[package]] -name = "env_filter" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -1182,12 +1159,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.28" @@ -1478,7 +1449,6 @@ dependencies = [ "console", "dialoguer", "directories", - "env_logger", "futures-util", "include_dir", "lune-roblox", @@ -1517,7 +1487,7 @@ dependencies = [ [[package]] name = "lune-std" -version = "0.1.0" +version = "0.1.1" dependencies = [ "lune-std-datetime", "lune-std-fs", @@ -1539,7 +1509,7 @@ dependencies = [ [[package]] name = "lune-std-datetime" -version = "0.1.0" +version = "0.1.1" dependencies = [ "chrono", "chrono_lc", diff --git a/crates/lune-roblox/src/datatypes/types/vector2.rs b/crates/lune-roblox/src/datatypes/types/vector2.rs index e0c352e..343fb70 100644 --- a/crates/lune-roblox/src/datatypes/types/vector2.rs +++ b/crates/lune-roblox/src/datatypes/types/vector2.rs @@ -80,6 +80,7 @@ impl LuaUserData for Vector2 { methods.add_meta_method(LuaMetaMethod::Sub, userdata_impl_sub); methods.add_meta_method(LuaMetaMethod::Mul, userdata_impl_mul_f32); methods.add_meta_method(LuaMetaMethod::Div, userdata_impl_div_f32); + methods.add_meta_method(LuaMetaMethod::IDiv, userdata_impl_idiv_f32); } } @@ -138,6 +139,20 @@ impl ops::Div for Vector2 { } } +impl IDiv for Vector2 { + type Output = Vector2; + fn idiv(self, rhs: Self) -> Self::Output { + Self((self.0 / rhs.0).floor()) + } +} + +impl IDiv for Vector2 { + type Output = Vector2; + fn idiv(self, rhs: f32) -> Self::Output { + Self((self.0 / rhs).floor()) + } +} + impl From for Vector2 { fn from(v: DomVector2) -> Self { Vector2(Vec2 { x: v.x, y: v.y }) diff --git a/crates/lune-roblox/src/datatypes/types/vector3.rs b/crates/lune-roblox/src/datatypes/types/vector3.rs index 32387d3..11bcd4a 100644 --- a/crates/lune-roblox/src/datatypes/types/vector3.rs +++ b/crates/lune-roblox/src/datatypes/types/vector3.rs @@ -141,6 +141,7 @@ impl LuaUserData for Vector3 { methods.add_meta_method(LuaMetaMethod::Sub, userdata_impl_sub); methods.add_meta_method(LuaMetaMethod::Mul, userdata_impl_mul_f32); methods.add_meta_method(LuaMetaMethod::Div, userdata_impl_div_f32); + methods.add_meta_method(LuaMetaMethod::IDiv, userdata_impl_idiv_f32); } } @@ -199,6 +200,20 @@ impl ops::Div for Vector3 { } } +impl IDiv for Vector3 { + type Output = Vector3; + fn idiv(self, rhs: Self) -> Self::Output { + Self((self.0 / rhs.0).floor()) + } +} + +impl IDiv for Vector3 { + type Output = Vector3; + fn idiv(self, rhs: f32) -> Self::Output { + Self((self.0 / rhs).floor()) + } +} + impl From for Vector3 { fn from(v: DomVector3) -> Self { Vector3(Vec3 { diff --git a/crates/lune-roblox/src/shared/userdata.rs b/crates/lune-roblox/src/shared/userdata.rs index 9184625..eaaa129 100644 --- a/crates/lune-roblox/src/shared/userdata.rs +++ b/crates/lune-roblox/src/shared/userdata.rs @@ -149,6 +149,37 @@ where }) } +pub trait IDiv { + type Output; + #[must_use] + fn idiv(self, rhs: Rhs) -> Self::Output; +} + +pub fn userdata_impl_idiv_f32(_: &Lua, datatype: &D, rhs: LuaValue) -> LuaResult +where + D: LuaUserData + IDiv + IDiv + Copy + 'static, +{ + match &rhs { + LuaValue::Number(n) => return Ok(datatype.idiv(*n as f32)), + LuaValue::Integer(i) => return Ok(datatype.idiv(*i as f32)), + LuaValue::UserData(ud) => { + if let Ok(vec) = ud.borrow::() { + return Ok(datatype.idiv(*vec)); + } + } + _ => {} + }; + Err(LuaError::FromLuaConversionError { + from: rhs.type_name(), + to: type_name::(), + message: Some(format!( + "Expected {} or number, got {}", + type_name::(), + rhs.type_name() + )), + }) +} + pub fn userdata_impl_div_i32(_: &Lua, datatype: &D, rhs: LuaValue) -> LuaResult where D: LuaUserData + ops::Div + ops::Div + Copy + 'static, diff --git a/crates/lune-std-datetime/Cargo.toml b/crates/lune-std-datetime/Cargo.toml index 6cb5499..efa5d32 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.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -16,7 +16,7 @@ workspace = true mlua = { version = "0.9.7", features = ["luau"] } thiserror = "1.0" -chrono = "=0.4.34" # NOTE: 0.4.35 does not compile with chrono_lc -chrono_lc = "0.1" +chrono = "0.4.38" +chrono_lc = "0.1.6" lune-utils = { version = "0.1.0", path = "../lune-utils" } diff --git a/crates/lune-std/Cargo.toml b/crates/lune-std/Cargo.toml index ed8416d..7ca38e4 100644 --- a/crates/lune-std/Cargo.toml +++ b/crates/lune-std/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lune-std" -version = "0.1.0" +version = "0.1.1" edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" @@ -47,7 +47,7 @@ tokio = { version = "1", default-features = false, features = ["fs", "sync"] } lune-utils = { version = "0.1.0", path = "../lune-utils" } -lune-std-datetime = { optional = true, version = "0.1.0", path = "../lune-std-datetime" } +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" } diff --git a/crates/lune/Cargo.toml b/crates/lune/Cargo.toml index 1afb52a..18a0d14 100644 --- a/crates/lune/Cargo.toml +++ b/crates/lune/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" license = "MPL-2.0" repository = "https://github.com/lune-org/lune" description = "A standalone Luau runtime" -readme = "README.md" +readme = "../../README.md" keywords = ["cli", "lua", "luau", "runtime"] categories = ["command-line-interface"] @@ -44,13 +44,7 @@ std = [ "std-task", ] -cli = [ - "dep:env_logger", - "dep:clap", - "dep:include_dir", - "dep:rustyline", - "dep:zip_next", -] +cli = ["dep:clap", "dep:include_dir", "dep:rustyline", "dep:zip_next"] [lints] workspace = true @@ -76,13 +70,12 @@ reqwest = { version = "0.11", default-features = false, features = [ "rustls-tls", ] } -lune-std = { optional = true, version = "0.1.0", path = "../lune-std" } +lune-std = { optional = true, version = "0.1.1", path = "../lune-std" } lune-roblox = { optional = true, version = "0.1.0", path = "../lune-roblox" } lune-utils = { version = "0.1.0", path = "../lune-utils" } ### CLI -env_logger = { optional = true, version = "0.11" } clap = { optional = true, version = "4.1", features = ["derive"] } include_dir = { optional = true, version = "0.7", features = ["glob"] } rustyline = { optional = true, version = "14.0" } diff --git a/tests/roblox/datatypes/Vector2.luau b/tests/roblox/datatypes/Vector2.luau index cccf373..1ed391e 100644 --- a/tests/roblox/datatypes/Vector2.luau +++ b/tests/roblox/datatypes/Vector2.luau @@ -39,4 +39,7 @@ assert(Vector2.new(2, 4) / Vector2.new(1, 2) == Vector2.new(2, 2)) assert(Vector2.new(2, 4) * 2 == Vector2.new(4, 8)) assert(Vector2.new(2, 4) / 2 == Vector2.new(1, 2)) +assert(Vector2.new(7, 15) // Vector2.new(3, 7) == Vector2.new(2, 2)) +assert(Vector2.new(3, 7) // 2 == Vector2.new(1, 3)) + -- TODO: Vector math diff --git a/tests/roblox/datatypes/Vector3.luau b/tests/roblox/datatypes/Vector3.luau index 64570aa..4a4b745 100644 --- a/tests/roblox/datatypes/Vector3.luau +++ b/tests/roblox/datatypes/Vector3.luau @@ -42,4 +42,7 @@ assert(Vector3.new(2, 4, 8) / Vector3.new(1, 1, 2) == Vector3.new(2, 4, 4)) assert(Vector3.new(2, 4, 8) * 2 == Vector3.new(4, 8, 16)) assert(Vector3.new(2, 4, 8) / 2 == Vector3.new(1, 2, 4)) +assert(Vector3.new(7, 11, 15) // Vector3.new(3, 5, 7) == Vector3.new(2, 2, 2)) +assert(Vector3.new(3, 5, 7) // 2 == Vector3.new(1, 2, 3)) + -- TODO: Vector math