refactor: use String instead of LuaString

This commit is contained in:
Erica Marigold 2023-09-04 12:31:04 +05:30
parent 1d83af9299
commit d9eca85ac2
No known key found for this signature in database
GPG key ID: 23CD97ABBBCC5ED2

View file

@ -40,8 +40,8 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
.with_function("fromLocalTime", |lua, date_time: LuaValue| { .with_function("fromLocalTime", |lua, date_time: LuaValue| {
Ok(DateTime::from_local_time(DateTimeBuilder::from_lua(date_time, lua).ok())) Ok(DateTime::from_local_time(DateTimeBuilder::from_lua(date_time, lua).ok()))
})? })?
.with_function("fromIsoDate", |_, iso_date: LuaString| { .with_function("fromIsoDate", |_, iso_date: String| {
Ok(DateTime::from_iso_date(iso_date.to_string_lossy())) Ok(DateTime::from_iso_date(iso_date))
})? })?
.build_readonly() .build_readonly()
} }
@ -68,7 +68,6 @@ impl LuaUserData for DateTime {
fields.add_field_method_get("unixTimestampMillis", |_, this| { fields.add_field_method_get("unixTimestampMillis", |_, this| {
Ok(this.unix_timestamp_millis) Ok(this.unix_timestamp_millis)
}); });
} }
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) { fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
@ -80,13 +79,9 @@ impl LuaUserData for DateTime {
methods.add_method( methods.add_method(
"formatTime", "formatTime",
|_, this, (timezone, fmt_str, locale): (LuaValue, LuaString, LuaString)| { |_, this, (timezone, fmt_str, locale): (LuaValue, String, String)| {
Ok(this Ok(this
.format_time( .format_time(Timezone::from_lua(timezone, &Lua::new())?, fmt_str, locale)
Timezone::from_lua(timezone, &Lua::new())?,
fmt_str.to_string_lossy(),
locale.to_string_lossy(),
)
.map_err(|()| LuaError::external("failed to parse DateTime object, invalid"))) .map_err(|()| LuaError::external("failed to parse DateTime object, invalid")))
}, },
); );