More inline const expressions

This commit is contained in:
Alex Orlenko
2024-08-29 22:05:28 +01:00
parent 3774296835
commit 5ebbc0868c
6 changed files with 11 additions and 12 deletions
+4 -5
View File
@@ -134,7 +134,7 @@ pub struct Compiler {
#[cfg(any(feature = "luau", doc))]
impl Default for Compiler {
fn default() -> Self {
Self::new()
const { Self::new() }
}
}
@@ -323,8 +323,8 @@ impl<'a> Chunk<'a> {
/// necessary to populate the environment in order for scripts using custom environments to be
/// useful.
pub fn set_environment(mut self, env: impl IntoLua) -> Self {
let lua = self.lua.lock();
let lua = lua.lua();
let guard = self.lua.lock();
let lua = guard.lua();
self.env = env
.into_lua(lua)
.and_then(|val| lua.unpack(val))
@@ -357,8 +357,7 @@ impl<'a> Chunk<'a> {
///
/// This is equivalent to calling the chunk function with no arguments and no return values.
pub fn exec(self) -> Result<()> {
self.call::<()>(())?;
Ok(())
self.call(())
}
/// Asynchronously execute this chunk of code.
+1 -1
View File
@@ -141,7 +141,7 @@ impl<T> Variadic<T> {
impl<T> Default for Variadic<T> {
fn default() -> Variadic<T> {
Variadic::new()
const { Variadic::new() }
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ pub struct Options {
impl Default for Options {
fn default() -> Self {
Self::new()
const { Self::new() }
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ pub struct Options {
impl Default for Options {
fn default() -> Self {
Self::new()
const { Self::new() }
}
}
+2 -2
View File
@@ -104,7 +104,7 @@ pub struct LuaOptions {
impl Default for LuaOptions {
fn default() -> Self {
LuaOptions::new()
const { LuaOptions::new() }
}
}
@@ -1251,7 +1251,7 @@ impl Lua {
///
/// This methods provides a way to add fields or methods to userdata objects of a type `T`.
pub fn register_userdata_type<T: 'static>(&self, f: impl FnOnce(&mut UserDataRegistry<T>)) -> Result<()> {
let mut registry = UserDataRegistry::new();
let mut registry = const { UserDataRegistry::new() };
f(&mut registry);
let lua = self.lock();
+2 -2
View File
@@ -723,7 +723,7 @@ impl RawLua {
}
// Create a new metatable from `UserData` definition
let mut registry = UserDataRegistry::new();
let mut registry = const { UserDataRegistry::new() };
T::register(&mut registry);
self.register_userdata_metatable(registry)
@@ -742,7 +742,7 @@ impl RawLua {
}
// Create an empty metatable
let registry = UserDataRegistry::new();
let registry = const { UserDataRegistry::new() };
self.register_userdata_metatable::<T>(registry)
})
}