Skip to content

Commit ca22ea3

Browse files
committed
Deprecate Debug::curr_line() in favour of Debug::current_line() that returns Option
1 parent cf05593 commit ca22ea3

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

src/debug.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,14 @@ impl<'a> Debug<'a> {
133133
}
134134
}
135135

136-
/// Corresponds to the `l` "what" mask. Returns the current line.
136+
#[doc(hidden)]
137+
#[deprecated(note = "Use `current_line` instead")]
137138
pub fn curr_line(&self) -> i32 {
139+
self.current_line().map(|n| n as i32).unwrap_or(-1)
140+
}
141+
142+
/// Corresponds to the `l` "what" mask. Returns the current line.
143+
pub fn current_line(&self) -> Option<usize> {
138144
unsafe {
139145
#[cfg(not(feature = "luau"))]
140146
mlua_assert!(
@@ -147,7 +153,7 @@ impl<'a> Debug<'a> {
147153
"lua_getinfo failed with `l`"
148154
);
149155

150-
(*self.ar).currentline
156+
linenumber_to_usize((*self.ar).currentline)
151157
}
152158
}
153159

src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl Lua {
577577
/// # fn main() -> Result<()> {
578578
/// let lua = Lua::new();
579579
/// lua.set_hook(HookTriggers::EVERY_LINE, |_lua, debug| {
580-
/// println!("line {}", debug.curr_line());
580+
/// println!("line {:?}", debug.current_line());
581581
/// Ok(VmState::Continue)
582582
/// });
583583
///

tests/hooks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn test_line_counts() -> Result<()> {
2424
let lua = Lua::new();
2525
lua.set_hook(HookTriggers::EVERY_LINE, move |_lua, debug| {
2626
assert_eq!(debug.event(), DebugEvent::Line);
27-
hook_output.lock().unwrap().push(debug.curr_line());
27+
hook_output.lock().unwrap().push(debug.current_line().unwrap());
2828
Ok(VmState::Continue)
2929
})?;
3030
lua.load(
@@ -240,7 +240,7 @@ fn test_hook_threads() -> Result<()> {
240240
let hook_output = output.clone();
241241
co.set_hook(HookTriggers::EVERY_LINE, move |_lua, debug| {
242242
assert_eq!(debug.event(), DebugEvent::Line);
243-
hook_output.lock().unwrap().push(debug.curr_line());
243+
hook_output.lock().unwrap().push(debug.current_line().unwrap());
244244
Ok(VmState::Continue)
245245
})?;
246246

tests/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ fn test_inspect_stack() -> Result<()> {
12831283
.inspect_stack(1, |debug| {
12841284
let source = debug.source().short_src;
12851285
let source = source.as_deref().unwrap_or("?");
1286-
let line = debug.curr_line();
1286+
let line = debug.current_line().unwrap();
12871287
format!("{}:{} {}", source, line, msg)
12881288
})
12891289
.unwrap();

0 commit comments

Comments
 (0)