summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2020-06-07 19:10:46 +0100
committerAlex Orlenko <zxteam@protonmail.com>2020-06-07 20:38:19 +0100
commitefcaef3db76e8e3b3a7f8e36805126d310543ee4 (patch)
treeecd42c764c7e594bc179bfed883025bcaefdc405 /src
parent0a13a9631d527e811d84920b575f4592fce958ae (diff)
downloadmlua-efcaef3db76e8e3b3a7f8e36805126d310543ee4.zip
Enable hooks support for LuaJIT
Diffstat (limited to 'src')
-rw-r--r--src/hook.rs13
-rw-r--r--src/lib.rs10
-rw-r--r--src/lua.rs33
3 files changed, 4 insertions, 52 deletions
diff --git a/src/hook.rs b/src/hook.rs
index bf3a26c..02e96cb 100644
--- a/src/hook.rs
+++ b/src/hook.rs
@@ -1,8 +1,3 @@
-#![cfg_attr(
- not(any(feature = "lua54", feature = "lua53", feature = "lua52", feature = "lua51")),
- allow(dead_code)
-)]
-
use std::ffi::CStr;
use std::marker::PhantomData;
use std::os::raw::{c_char, c_int};
@@ -18,8 +13,6 @@ use crate::util::callback_error;
/// Lua code executing at the time that the hook function was called. Further information can be
/// found in the [Lua 5.3 documentaton][lua_doc].
///
-/// Requires `feature = "lua54/lua53/lua52/lua51"`
-///
/// [lua_doc]: https://www.lua.org/manual/5.3/manual.html#lua_Debug
/// [`Lua::set_hook`]: struct.Lua.html#method.set_hook
#[derive(Clone)]
@@ -93,9 +86,9 @@ impl<'a> Debug<'a> {
);
DebugStack {
num_ups: (*self.ar).nups as i32,
- #[cfg(any(feature = "lua52", feature = "lua53", feature = "lua54"))]
+ #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
num_params: (*self.ar).nparams as i32,
- #[cfg(any(feature = "lua52", feature = "lua53", feature = "lua54"))]
+ #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
is_vararg: (*self.ar).isvararg != 0,
}
}
@@ -129,8 +122,6 @@ pub struct DebugStack {
}
/// Determines when a hook function will be called by Lua.
-///
-/// Requires `feature = "lua54/lua53/lua52/lua51"`
#[derive(Clone, Copy, Debug, Default)]
pub struct HookTriggers {
/// Before a function call.
diff --git a/src/lib.rs b/src/lib.rs
index b4b6606..ce60d6c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -80,6 +80,7 @@ pub use crate::ffi::lua_State;
pub use crate::error::{Error, ExternalError, ExternalResult, Result};
pub use crate::function::Function;
+pub use crate::hook::{Debug, DebugNames, DebugSource, DebugStack, HookTriggers};
pub use crate::lua::{Chunk, GCMode, Lua};
pub use crate::multi::Variadic;
pub use crate::scope::Scope;
@@ -91,15 +92,6 @@ pub use crate::types::{Integer, LightUserData, Number, RegistryKey};
pub use crate::userdata::{AnyUserData, MetaMethod, UserData, UserDataMethods};
pub use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Value};
-#[cfg(any(
- feature = "lua54",
- feature = "lua53",
- feature = "lua52",
- feature = "lua51",
- doc
-))]
-pub use crate::hook::{Debug, DebugNames, DebugSource, DebugStack, HookTriggers};
-
#[cfg(feature = "async")]
pub use crate::thread::AsyncThread;
diff --git a/src/lua.rs b/src/lua.rs
index ad81558..449a499 100644
--- a/src/lua.rs
+++ b/src/lua.rs
@@ -10,6 +10,7 @@ use std::{mem, ptr, str};
use crate::error::{Error, Result};
use crate::ffi;
use crate::function::Function;
+use crate::hook::{hook_proc, Debug, HookTriggers};
use crate::scope::Scope;
use crate::stdlib::StdLib;
use crate::string::String;
@@ -27,15 +28,6 @@ use crate::util::{
};
use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti, Value};
-#[cfg(any(
- feature = "lua54",
- feature = "lua53",
- feature = "lua52",
- feature = "lua51",
- doc
-))]
-use crate::hook::{hook_proc, Debug, HookTriggers};
-
#[cfg(feature = "async")]
use {
crate::types::AsyncCallback,
@@ -430,16 +422,12 @@ impl Lua {
/// limited form of execution limits by setting [`HookTriggers.every_nth_instruction`] and
/// erroring once an instruction limit has been reached.
///
- /// Requires `feature = "lua54/lua53/lua52/lua51"`
- ///
/// # Example
///
/// Shows each line number of code being executed by the Lua interpreter.
///
/// ```
- /// # #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52", feature = "lua51"))]
/// # use mlua::{Lua, HookTriggers, Result};
- /// # #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52", feature = "lua51"))]
/// # fn main() -> Result<()> {
/// let lua = Lua::new();
/// lua.set_hook(HookTriggers {
@@ -455,20 +443,10 @@ impl Lua {
/// local z = string.len(x..", "..y)
/// "#).exec()
/// # }
- ///
- /// # #[cfg(not(any(feature = "lua54", feature = "lua53", feature = "lua52", feature = "lua51")))]
- /// # fn main() {}
/// ```
///
/// [`HookTriggers`]: struct.HookTriggers.html
/// [`HookTriggers.every_nth_instruction`]: struct.HookTriggers.html#field.every_nth_instruction
- #[cfg(any(
- feature = "lua54",
- feature = "lua53",
- feature = "lua52",
- feature = "lua51",
- doc
- ))]
pub fn set_hook<F>(&self, triggers: HookTriggers, callback: F) -> Result<()>
where
F: 'static + MaybeSend + FnMut(&Lua, Debug) -> Result<()>,
@@ -484,15 +462,6 @@ impl Lua {
/// Remove any hook previously set by `set_hook`. This function has no effect if a hook was not
/// previously set.
- ///
- /// Requires `feature = "lua54/lua53/lua52/lua51"`
- #[cfg(any(
- feature = "lua54",
- feature = "lua53",
- feature = "lua52",
- feature = "lua51",
- doc
- ))]
pub fn remove_hook(&self) {
// If main_state is not available, then sethook wasn't called.
let state = match self.main_state {