Skip to content

Commit b58d89e

Browse files
committed
clean code
1 parent c4f99dc commit b58d89e

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

crates/luars/src/gc/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ mod paged_pool;
4141
mod string_interner;
4242
mod table_allocator;
4343

44+
#[cfg(debug_assertions)]
45+
use std::collections::HashMap;
46+
4447
use crate::{
4548
LuaRawTable, LuaResult,
4649
lua_value::LuaValue,
@@ -3458,7 +3461,7 @@ impl GC {
34583461
#[cfg(debug_assertions)]
34593462
fn validate_not_on_stack(
34603463
gc_owner: &GcObjectOwner,
3461-
stack_ptrs: &std::collections::HashMap<u64, (String, usize, usize, u8)>,
3464+
stack_ptrs: &HashMap<u64, (String, usize, usize, u8)>,
34623465
old_list: &GcList,
34633466
) {
34643467
let raw_ptr = match gc_owner {

crates/luars/src/stdlib/debug.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
use crate::compiler::format_source;
55
use crate::lib_registry::LibraryModule;
66
use crate::lua_value::{LuaProto, LuaValue};
7+
use crate::lua_vm::call_info::call_status;
78
use crate::lua_vm::opcode::OpCode;
8-
use crate::lua_vm::{LuaError, LuaResult, LuaState, get_metatable};
9-
use crate::{Instruction, LUA_MASKCALL, LUA_MASKLINE, LUA_MASKRET};
9+
use crate::lua_vm::{LuaError, LuaResult, LuaState, TmKind, get_metatable};
10+
use crate::{Instruction, LUA_MASKCALL, LUA_MASKCOUNT, LUA_MASKLINE, LUA_MASKRET, lib_module};
1011

1112
/// Get the type name of an object, checking __name in metatable first.
1213
/// Mirrors C Lua's luaT_objtypename.
@@ -315,7 +316,6 @@ fn funcnamefromcode(chunk: &LuaProto, pc: usize) -> Option<(&'static str, String
315316
Some(("metamethod", "newindex".to_string()))
316317
}
317318
OpCode::MmBin | OpCode::MmBinI | OpCode::MmBinK => {
318-
use crate::lua_vm::TmKind;
319319
let tm = TmKind::from_u8(i.get_c() as u8);
320320
let name: &str = tm.name();
321321
Some(("metamethod", name[2..].to_string()))
@@ -347,7 +347,7 @@ fn getfuncname(l: &LuaState, ci_frame_idx: usize) -> Option<(&'static str, Strin
347347
// Look at the immediately previous frame (the caller)
348348
let prev_idx = ci_frame_idx - 1;
349349
let prev = l.get_frame(prev_idx)?;
350-
if prev.call_status & crate::lua_vm::call_info::call_status::CIST_HOOKED != 0 {
350+
if prev.call_status & call_status::CIST_HOOKED != 0 {
351351
return Some(("hook", "?".to_string()));
352352
}
353353
if prev.is_lua() {
@@ -672,7 +672,7 @@ pub fn opinterror(
672672
}
673673

674674
/// Generate a comparison error (mirrors luaG_ordererror).
675-
pub fn ordererror(l: &mut LuaState, p1: &crate::LuaValue, p2: &crate::LuaValue) -> LuaError {
675+
pub fn ordererror(l: &mut LuaState, p1: &LuaValue, p2: &LuaValue) -> LuaError {
676676
let t1 = objtypename(l, p1);
677677
let t2 = objtypename(l, p2);
678678
if t1 == t2 {
@@ -684,7 +684,7 @@ pub fn ordererror(l: &mut LuaState, p1: &crate::LuaValue, p2: &crate::LuaValue)
684684

685685
/// Generate a call error with function name info (mirrors luaG_callerror).
686686
/// Used when attempting to call a non-callable value.
687-
pub fn callerror(l: &mut LuaState, val: &crate::LuaValue) -> LuaError {
687+
pub fn callerror(l: &mut LuaState, val: &LuaValue) -> LuaError {
688688
// Look at the current frame's instruction to determine what was being called
689689
let ci_idx = l.call_depth().wrapping_sub(1);
690690
if let Some(ci) = l.get_frame(ci_idx)
@@ -714,7 +714,7 @@ pub fn pub_getfuncname(l: &LuaState, ci_frame_idx: usize) -> Option<(&'static st
714714
}
715715

716716
pub fn create_debug_lib() -> LibraryModule {
717-
let mut module = crate::lib_module!("debug", {
717+
let mut module = lib_module!("debug", {
718718
"traceback" => debug_traceback,
719719
"getinfo" => debug_getinfo,
720720
"getmetatable" => debug_getmetatable,
@@ -1203,9 +1203,9 @@ fn debug_sethook(l: &mut LuaState) -> LuaResult<usize> {
12031203
{
12041204
for ch in s.chars() {
12051205
match ch {
1206-
'c' => mask |= crate::lua_vm::LUA_MASKCALL,
1207-
'r' => mask |= crate::lua_vm::LUA_MASKRET,
1208-
'l' => mask |= crate::lua_vm::LUA_MASKLINE,
1206+
'c' => mask |= LUA_MASKCALL,
1207+
'r' => mask |= LUA_MASKRET,
1208+
'l' => mask |= LUA_MASKLINE,
12091209
_ => {} // ignore unknown characters
12101210
}
12111211
}
@@ -1214,7 +1214,7 @@ fn debug_sethook(l: &mut LuaState) -> LuaResult<usize> {
12141214
// Parse count
12151215
let count = count_val.and_then(|v| v.as_integer()).unwrap_or(0) as i32;
12161216
if count > 0 {
1217-
mask |= crate::lua_vm::LUA_MASKCOUNT;
1217+
mask |= LUA_MASKCOUNT;
12181218
}
12191219

12201220
// If hook is nil, clear everything

0 commit comments

Comments
 (0)