Lint
This commit is contained in:
1 parent
aa1bfb768e
commit
20a1db073d
20 files changed
+118
-126
No files matched your search
+4
-4
@@ -202,10 +202,10 @@ pub enum Input {
|
||||
impl Input {
|
||||
fn as_pob_key_str(&self) -> Option<SmolStr> {
|
||||
match self {
|
||||
Input::Keyboard(key) => key_as_str(key.clone()),
|
||||
Input::Mouse(button) => mousebutton_as_str(*button),
|
||||
Input::WheelUp => Some("WHEELUP".into()),
|
||||
Input::WheelDown => Some("WHEELDOWN".into()),
|
||||
Self::Keyboard(key) => key_as_str(key.clone()),
|
||||
Self::Mouse(button) => mousebutton_as_str(*button),
|
||||
Self::WheelUp => Some("WHEELUP".into()),
|
||||
Self::WheelDown => Some("WHEELDOWN".into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-21
@@ -21,7 +21,7 @@ impl ImageHandle {
|
||||
Self { texture: None }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub fn texture_id(&self) -> Option<TextureId> {
|
||||
self.texture.as_ref().map(TextureHandle::id)
|
||||
}
|
||||
@@ -33,18 +33,15 @@ impl ImageHandle {
|
||||
|
||||
#[inline]
|
||||
pub fn is_loading(&self) -> bool {
|
||||
match &self.texture {
|
||||
Some(texture) => texture.is_loading(),
|
||||
None => true,
|
||||
}
|
||||
self.texture.as_ref().is_none_or(TextureHandle::is_loading)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn image_size(&self) -> PhysicalSize<u32> {
|
||||
match &self.texture {
|
||||
Some(texture) => texture.size().unwrap_or(PhysicalSize::zero()),
|
||||
None => PhysicalSize::zero(),
|
||||
}
|
||||
self.texture
|
||||
.as_ref()
|
||||
.and_then(TextureHandle::size)
|
||||
.unwrap_or_else(PhysicalSize::zero)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +59,7 @@ const IMAGE_HANDLE_METATABLE: &[u8] = b"runtime.ImageHandle\0";
|
||||
#[inline]
|
||||
unsafe fn push_image_handle(state: *mut ffi::lua_State) -> *mut ImageHandle {
|
||||
let ptr = unsafe { ffi::lua_newuserdata(state, std::mem::size_of::<ImageHandle>()) }
|
||||
as *mut ImageHandle;
|
||||
.cast::<ImageHandle>();
|
||||
|
||||
// Construct the Rust object directly in Lua-owned memory
|
||||
unsafe {
|
||||
@@ -78,7 +75,7 @@ unsafe extern "C-unwind" fn new_image_handle(state: *mut ffi::lua_State) -> c_in
|
||||
push_image_handle(state);
|
||||
|
||||
// The metatable must already have been registered.
|
||||
ffi::luaL_getmetatable(state, IMAGE_HANDLE_METATABLE.as_ptr() as *const _);
|
||||
ffi::luaL_getmetatable(state, IMAGE_HANDLE_METATABLE.as_ptr().cast());
|
||||
ffi::lua_setmetatable(state, -2);
|
||||
}
|
||||
|
||||
@@ -89,12 +86,12 @@ unsafe extern "C-unwind" fn new_image_handle(state: *mut ffi::lua_State) -> c_in
|
||||
#[inline]
|
||||
unsafe fn get_image_handle(state: *mut ffi::lua_State, index: c_int) -> *mut ImageHandle {
|
||||
unsafe {
|
||||
ffi::luaL_checkudata(state, index, IMAGE_HANDLE_METATABLE.as_ptr() as *const _)
|
||||
as *mut ImageHandle
|
||||
ffi::luaL_checkudata(state, index, IMAGE_HANDLE_METATABLE.as_ptr().cast())
|
||||
.cast::<ImageHandle>()
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[inline]
|
||||
pub unsafe fn image_handle_texture_id(
|
||||
state: *mut ffi::lua_State,
|
||||
index: c_int,
|
||||
@@ -103,7 +100,7 @@ pub unsafe fn image_handle_texture_id(
|
||||
return None;
|
||||
}
|
||||
|
||||
let ptr = unsafe { ffi::lua_touserdata(state, index) } as *const ImageHandle;
|
||||
let ptr = unsafe { ffi::lua_touserdata(state, index) }.cast::<ImageHandle>();
|
||||
|
||||
if ptr.is_null() {
|
||||
return None;
|
||||
@@ -114,7 +111,7 @@ pub unsafe fn image_handle_texture_id(
|
||||
|
||||
// Drops the `ImageHandle`
|
||||
unsafe extern "C-unwind" fn image_handle_gc(state: *mut ffi::lua_State) -> c_int {
|
||||
let ptr = unsafe { ffi::lua_touserdata(state, 1) } as *mut ImageHandle;
|
||||
let ptr = unsafe { ffi::lua_touserdata(state, 1) }.cast::<ImageHandle>();
|
||||
|
||||
if !ptr.is_null() {
|
||||
unsafe {
|
||||
@@ -131,7 +128,7 @@ unsafe extern "C-unwind" fn image_handle_is_valid(state: *mut ffi::lua_State) ->
|
||||
let valid = unsafe { (*handle).is_valid() };
|
||||
|
||||
unsafe {
|
||||
ffi::lua_pushboolean(state, valid as c_int);
|
||||
ffi::lua_pushboolean(state, c_int::from(valid));
|
||||
}
|
||||
|
||||
1
|
||||
@@ -143,7 +140,7 @@ unsafe extern "C-unwind" fn image_handle_is_loading(state: *mut ffi::lua_State)
|
||||
let loading = unsafe { (*handle).is_loading() };
|
||||
|
||||
unsafe {
|
||||
ffi::lua_pushboolean(state, loading as c_int);
|
||||
ffi::lua_pushboolean(state, c_int::from(loading));
|
||||
}
|
||||
|
||||
1
|
||||
@@ -211,12 +208,12 @@ unsafe extern "C-unwind" fn image_handle_load(state: *mut ffi::lua_State) -> c_i
|
||||
|
||||
let mut len = 0;
|
||||
|
||||
let ptr = unsafe { ffi::lua_tolstring(state, index, &mut len) };
|
||||
let ptr = unsafe { ffi::lua_tolstring(state, index, &raw mut len) };
|
||||
if ptr.is_null() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let bytes = unsafe { std::slice::from_raw_parts(ptr as *const u8, len) };
|
||||
let bytes = unsafe { std::slice::from_raw_parts(ptr.cast::<u8>(), len) };
|
||||
|
||||
match bytes {
|
||||
b"CLAMP" => {
|
||||
@@ -268,7 +265,7 @@ unsafe extern "C-unwind" fn image_handle_load(state: *mut ffi::lua_State) -> c_i
|
||||
|
||||
unsafe fn register_image_handle_metatable(state: *mut ffi::lua_State) {
|
||||
unsafe {
|
||||
let created = ffi::luaL_newmetatable(state, IMAGE_HANDLE_METATABLE.as_ptr() as *const _);
|
||||
let created = ffi::luaL_newmetatable(state, IMAGE_HANDLE_METATABLE.as_ptr().cast());
|
||||
|
||||
// Create metatable if it doesn't exist already
|
||||
if created != 0 {
|
||||
|
||||
@@ -14,20 +14,17 @@ pub fn get_user_path(l: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
// parent directory of Launch.lua script
|
||||
pub fn get_script_path(l: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
let ctx = l.app_data_ref::<Context>().unwrap();
|
||||
Ok(ctx.script_dir.to_owned())
|
||||
Ok(ctx.script_dir.clone())
|
||||
}
|
||||
|
||||
// parent directory of executable
|
||||
pub fn get_runtime_path(_: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
match get_executable_dir() {
|
||||
Ok(exe_path) => Ok(exe_path),
|
||||
Err(_) => Ok(PathBuf::new()),
|
||||
}
|
||||
Ok(get_executable_dir().unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn get_work_dir(l: &Lua, _: ()) -> LuaResult<PathBuf> {
|
||||
let ctx = l.app_data_ref::<Context>().unwrap();
|
||||
Ok(ctx.current_working_dir.to_owned())
|
||||
Ok(ctx.current_working_dir.clone())
|
||||
}
|
||||
|
||||
// NOTE: unused
|
||||
|
||||
@@ -14,7 +14,7 @@ macro_rules! str_from_stack {
|
||||
unsafe {
|
||||
let mut size = 0;
|
||||
let data = ffi::luaL_checklstring($s, $i, &mut size);
|
||||
let bytes = std::slice::from_raw_parts(data as *const u8, size);
|
||||
let bytes = std::slice::from_raw_parts(data.cast::<u8>(), size);
|
||||
std::str::from_utf8_unchecked(bytes)
|
||||
}
|
||||
};
|
||||
@@ -74,10 +74,10 @@ pub unsafe extern "C-unwind" fn get_draw_color(state: *mut ffi::lua_State) -> c_
|
||||
let ctx = lua_instance.app_data_ref::<Context>().unwrap();
|
||||
|
||||
let color: [f32; 4] = ctx.recorder.get_draw_color().into();
|
||||
unsafe { ffi::lua_pushnumber(state, color[0] as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, color[1] as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, color[2] as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, color[3] as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, f64::from(color[0])) };
|
||||
unsafe { ffi::lua_pushnumber(state, f64::from(color[1])) };
|
||||
unsafe { ffi::lua_pushnumber(state, f64::from(color[2])) };
|
||||
unsafe { ffi::lua_pushnumber(state, f64::from(color[3])) };
|
||||
|
||||
4
|
||||
}
|
||||
|
||||
@@ -64,16 +64,19 @@ impl UserData for SearchHandle {
|
||||
methods.add_method_mut("GetFileName", |l, this, ()| {
|
||||
Ok(this.current.as_ref().unwrap().file_name().into_lua(l))
|
||||
});
|
||||
methods.add_method("GetFileSize", |_, this, ()| match &this.current {
|
||||
Some(path) => match fs::metadata(path) {
|
||||
Ok(metadata) => Ok(metadata.len()),
|
||||
Err(_) => Ok(0),
|
||||
},
|
||||
None => Ok(0),
|
||||
methods.add_method("GetFileSize", |_, this, ()| {
|
||||
Ok(this
|
||||
.current
|
||||
.as_ref()
|
||||
.and_then(|path| fs::metadata(path).ok())
|
||||
.map_or(0, |metadata| metadata.len()))
|
||||
});
|
||||
methods.add_method("GetFileModifiedTime", |_, this, ()| match &this.current {
|
||||
Some(path) => get_time_modified(path).map_or(Ok(0), Ok),
|
||||
None => Ok(0),
|
||||
methods.add_method("GetFileModifiedTime", |_, this, ()| {
|
||||
Ok(this
|
||||
.current
|
||||
.as_ref()
|
||||
.and_then(|path| get_time_modified(path).ok())
|
||||
.unwrap_or(0))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+26
-29
@@ -19,7 +19,7 @@ macro_rules! str_from_stack {
|
||||
unsafe {
|
||||
let mut size = 0;
|
||||
let data = ffi::luaL_checklstring($s, $i, &mut size);
|
||||
let bytes = std::slice::from_raw_parts(data as *const u8, size);
|
||||
let bytes = std::slice::from_raw_parts(data.cast::<u8>(), size);
|
||||
std::str::from_utf8_unchecked(bytes)
|
||||
}
|
||||
};
|
||||
@@ -140,7 +140,7 @@ pub unsafe extern "C-unwind" fn get_string_width(state: *mut ffi::lua_State) ->
|
||||
.layout(job, ctx.window_state.scale_factor());
|
||||
let width = layout.width();
|
||||
|
||||
unsafe { ffi::lua_pushnumber(state, width as f64) };
|
||||
unsafe { ffi::lua_pushnumber(state, f64::from(width)) };
|
||||
1
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ impl<'a> IntoIterator for PoBString<'a> {
|
||||
}
|
||||
|
||||
/// A segment of text that shares the same color.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub struct ColoredSegment<'a> {
|
||||
pub color: Option<Srgba>,
|
||||
pub text: &'a str,
|
||||
@@ -353,36 +353,33 @@ impl<'a> Iterator for PoBStringSegmentIterator<'a> {
|
||||
}
|
||||
|
||||
loop {
|
||||
match self.captures.next() {
|
||||
Some(captures) => {
|
||||
let m = &captures.get(0).expect("group 0 always matches");
|
||||
let start = self.cursor;
|
||||
let text = &self.haystack[start..m.start()];
|
||||
let color = self.color;
|
||||
if let Some(captures) = self.captures.next() {
|
||||
let m = &captures.get(0).expect("group 0 always matches");
|
||||
let start = self.cursor;
|
||||
let text = &self.haystack[start..m.start()];
|
||||
let color = self.color;
|
||||
|
||||
self.cursor = m.end();
|
||||
self.color = Some(Srgba::from_escape_code(m.as_str()));
|
||||
self.cursor = m.end();
|
||||
self.color = Some(Srgba::from_escape_code(m.as_str()));
|
||||
|
||||
// check for case where string starts with escape code
|
||||
if text.is_empty() && color.is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
return Some(ColoredSegment {
|
||||
color,
|
||||
text,
|
||||
original_start: start,
|
||||
});
|
||||
}
|
||||
None => {
|
||||
self.done = true;
|
||||
return Some(ColoredSegment {
|
||||
color: self.color,
|
||||
text: &self.haystack[self.cursor..],
|
||||
original_start: self.cursor,
|
||||
});
|
||||
// check for case where string starts with escape code
|
||||
if text.is_empty() && color.is_none() {
|
||||
continue;
|
||||
}
|
||||
|
||||
return Some(ColoredSegment {
|
||||
color,
|
||||
text,
|
||||
original_start: start,
|
||||
});
|
||||
}
|
||||
|
||||
self.done = true;
|
||||
return Some(ColoredSegment {
|
||||
color: self.color,
|
||||
text: &self.haystack[self.cursor..],
|
||||
original_start: self.cursor,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,10 +191,9 @@ impl Subscript {
|
||||
///
|
||||
/// Does nothing if there is no pending call.
|
||||
fn handle_calls(&self, lua: &Lua) {
|
||||
let call = match self.call_rx.try_recv() {
|
||||
Ok(call) => call,
|
||||
let Ok(call) = self.call_rx.try_recv() else {
|
||||
// no pending call, or thread disconnected which is handled on join
|
||||
Err(_) => return,
|
||||
return;
|
||||
};
|
||||
|
||||
match call {
|
||||
|
||||
Reference in new issue
Block a user