diff --git a/packages/lib-roblox/src/datatypes/types/color_sequence.rs b/packages/lib-roblox/src/datatypes/types/color_sequence.rs index 742dc30..f7e4fdc 100644 --- a/packages/lib-roblox/src/datatypes/types/color_sequence.rs +++ b/packages/lib-roblox/src/datatypes/types/color_sequence.rs @@ -5,7 +5,7 @@ use rbx_dom_weak::types::{ ColorSequence as RbxColorSequence, ColorSequenceKeypoint as RbxColorSequenceKeypoint, }; -use super::{Color3, ColorSequenceKeypoint}; +use super::{super::*, Color3, ColorSequenceKeypoint}; /** An implementation of the [ColorSequence](https://create.roblox.com/docs/reference/engine/datatypes/ColorSequence) Roblox datatype. @@ -62,6 +62,11 @@ impl LuaUserData for ColorSequence { fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) { fields.add_field_method_get("Keypoints", |_, this| Ok(this.keypoints.clone())); } + + fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); + methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); + } } impl fmt::Display for ColorSequence { diff --git a/packages/lib-roblox/src/datatypes/types/color_sequence_keypoint.rs b/packages/lib-roblox/src/datatypes/types/color_sequence_keypoint.rs index 8b7fe8e..1bd84d6 100644 --- a/packages/lib-roblox/src/datatypes/types/color_sequence_keypoint.rs +++ b/packages/lib-roblox/src/datatypes/types/color_sequence_keypoint.rs @@ -3,7 +3,7 @@ use core::fmt; use mlua::prelude::*; use rbx_dom_weak::types::ColorSequenceKeypoint as RbxColorSequenceKeypoint; -use super::Color3; +use super::{super::*, Color3}; /** An implementation of the [ColorSequenceKeypoint](https://create.roblox.com/docs/reference/engine/datatypes/ColorSequenceKeypoint) Roblox datatype. @@ -33,6 +33,11 @@ impl LuaUserData for ColorSequenceKeypoint { fields.add_field_method_get("Time", |_, this| Ok(this.time)); fields.add_field_method_get("Value", |_, this| Ok(this.color)); } + + fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_meta_method(LuaMetaMethod::Eq, userdata_impl_eq); + methods.add_meta_method(LuaMetaMethod::ToString, userdata_impl_to_string); + } } impl fmt::Display for ColorSequenceKeypoint { diff --git a/packages/lib-roblox/src/tests.rs b/packages/lib-roblox/src/tests.rs index 330abb4..725e2c3 100644 --- a/packages/lib-roblox/src/tests.rs +++ b/packages/lib-roblox/src/tests.rs @@ -38,13 +38,15 @@ macro_rules! create_tests { } create_tests! { - datatypes_brick_color: "datatypes/BrickColor", - datatypes_color3: "datatypes/Color3", - datatypes_enum: "datatypes/Enum", - datatypes_udim: "datatypes/UDim", - datatypes_udim2: "datatypes/UDim2", - datatypes_vector2: "datatypes/Vector2", - datatypes_vector2int16: "datatypes/Vector2int16", - datatypes_vector3: "datatypes/Vector3", - datatypes_vector3int16: "datatypes/Vector3int16", + datatypes_brick_color: "datatypes/BrickColor", + datatypes_color3: "datatypes/Color3", + datatypes_color_sequence: "datatypes/ColorSequence", + datatypes_color_sequence_keypoint: "datatypes/ColorSequenceKeypoint", + datatypes_enum: "datatypes/Enum", + datatypes_udim: "datatypes/UDim", + datatypes_udim2: "datatypes/UDim2", + datatypes_vector2: "datatypes/Vector2", + datatypes_vector2int16: "datatypes/Vector2int16", + datatypes_vector3: "datatypes/Vector3", + datatypes_vector3int16: "datatypes/Vector3int16", } diff --git a/tests/roblox/datatypes/ColorSequence.luau b/tests/roblox/datatypes/ColorSequence.luau new file mode 100644 index 0000000..bae5cd7 --- /dev/null +++ b/tests/roblox/datatypes/ColorSequence.luau @@ -0,0 +1,36 @@ +-- HACK: Make luau happy, with the mlua rust +-- crate all globals are also present in _G +local Color3 = _G.Color3 +local ColorSequence = _G.ColorSequence +local ColorSequenceKeypoint = _G.ColorSequenceKeypoint + +-- Constructors & properties + +ColorSequence.new(Color3.new()) +ColorSequence.new(Color3.new(), Color3.new()) +local sequence = ColorSequence.new({ + ColorSequenceKeypoint.new(0, Color3.new(1, 0, 0)), + ColorSequenceKeypoint.new(0.5, Color3.new(0, 1, 0)), + ColorSequenceKeypoint.new(1, Color3.new(0, 0, 1)), +}) + +assert(not pcall(function() + return ColorSequence.new() +end)) +assert(not pcall(function() + return ColorSequence.new(0.5) +end)) +assert(not pcall(function() + return ColorSequence.new(false) +end)) +assert(not pcall(function() + return ColorSequence.new("", "") +end)) +assert(not pcall(function() + return ColorSequence.new(newproxy(true)) +end)) + +assert(#sequence.Keypoints == 3) +assert(sequence.Keypoints[1] == ColorSequenceKeypoint.new(0, Color3.new(1, 0, 0))) +assert(sequence.Keypoints[2] == ColorSequenceKeypoint.new(0.5, Color3.new(0, 1, 0))) +assert(sequence.Keypoints[3] == ColorSequenceKeypoint.new(1, Color3.new(0, 0, 1))) diff --git a/tests/roblox/datatypes/ColorSequenceKeypoint.luau b/tests/roblox/datatypes/ColorSequenceKeypoint.luau new file mode 100644 index 0000000..d43560f --- /dev/null +++ b/tests/roblox/datatypes/ColorSequenceKeypoint.luau @@ -0,0 +1,30 @@ +-- HACK: Make luau happy, with the mlua rust +-- crate all globals are also present in _G +local Color3 = _G.Color3 +local ColorSequenceKeypoint = _G.ColorSequenceKeypoint + +-- Constructors & properties + +ColorSequenceKeypoint.new(0, Color3.new()) +ColorSequenceKeypoint.new(1, Color3.new()) + +assert(not pcall(function() + return ColorSequenceKeypoint.new() +end)) +assert(not pcall(function() + return ColorSequenceKeypoint.new(0.5) +end)) +assert(not pcall(function() + return ColorSequenceKeypoint.new(false) +end)) +assert(not pcall(function() + return ColorSequenceKeypoint.new("", "") +end)) +assert(not pcall(function() + return ColorSequenceKeypoint.new(newproxy(true)) +end)) + +assert(ColorSequenceKeypoint.new(0, Color3.new()).Time == 0) +assert(ColorSequenceKeypoint.new(1, Color3.new()).Time == 1) +assert(ColorSequenceKeypoint.new(0, Color3.new()).Value == Color3.new()) +assert(ColorSequenceKeypoint.new(1, Color3.new(1)).Value == Color3.new(1))