Update docs

This commit is contained in:
Alex Orlenko 2022-03-25 00:23:35 +00:00
parent 714dd6249f
commit ec1fa04085
No known key found for this signature in database
GPG Key ID: 4C150C250863B96D
11 changed files with 34 additions and 23 deletions

View File

@ -64,7 +64,8 @@ pub enum ChunkMode {
}
/// Luau compiler
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
#[derive(Clone, Copy, Debug)]
pub struct Compiler {
optimization_level: u8,
@ -72,7 +73,7 @@ pub struct Compiler {
coverage_level: u8,
}
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
impl Default for Compiler {
fn default() -> Self {
// Defaults are taken from luacode.h
@ -84,7 +85,7 @@ impl Default for Compiler {
}
}
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
impl Compiler {
/// Creates Luau compiler instance with default options
pub fn new() -> Self {
@ -97,7 +98,6 @@ impl Compiler {
/// 0 - no optimization
/// 1 - baseline optimization level that doesn't prevent debuggability (default)
/// 2 - includes optimizations that harm debuggability such as inlining
#[cfg(feature = "luau")]
pub fn set_optimization_level(mut self, level: u8) -> Self {
self.optimization_level = level;
self
@ -109,7 +109,6 @@ impl Compiler {
/// 0 - no debugging support
/// 1 - line info & function names only; sufficient for backtraces (default)
/// 2 - full debug info with local & upvalue names; necessary for debugger
#[cfg(feature = "luau")]
pub fn set_debug_level(mut self, level: u8) -> Self {
self.debug_level = level;
self
@ -121,7 +120,6 @@ impl Compiler {
/// 0 - no code coverage support (default)
/// 1 - statement coverage
/// 2 - statement and expression coverage (verbose)
#[cfg(feature = "luau")]
pub fn set_coverage_level(mut self, level: u8) -> Self {
self.coverage_level = level;
self
@ -190,7 +188,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
/// See [`Compiler::set_optimization_level`] for details.
///
/// Requires `feature = "luau`
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
pub fn set_optimization_level(mut self, level: u8) -> Self {
self.compiler
.get_or_insert_with(Default::default)
@ -203,7 +202,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
/// See [`Compiler::set_debug_level`] for details.
///
/// Requires `feature = "luau`
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
pub fn set_debug_level(mut self, level: u8) -> Self {
self.compiler
.get_or_insert_with(Default::default)
@ -216,7 +216,8 @@ impl<'lua, 'a> Chunk<'lua, 'a> {
/// See [`Compiler::set_coverage_level`] for details.
///
/// Requires `feature = "luau`
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
pub fn set_coverage_level(mut self, level: u8) -> Self {
self.compiler
.get_or_insert_with(Default::default)

View File

@ -37,7 +37,8 @@ pub enum Error {
/// Lua garbage collector error, aka `LUA_ERRGCMM`.
///
/// The Lua VM returns this error when there is an error running a `__gc` metamethod.
#[cfg(any(feature = "lua53", feature = "lua52"))]
#[cfg(any(feature = "lua53", feature = "lua52", doc))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "lua53", feature = "lua52"))))]
GarbageCollectorError(StdString),
/// Potentially unsafe action in safe mode.
SafetyError(StdString),

View File

@ -214,6 +214,7 @@ impl<'lua> Function<'lua> {
/// If `strip` is true, the binary representation may not include all debug information
/// about the function, to save space.
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub fn dump(&self, strip: bool) -> Vec<u8> {
use std::os::raw::c_void;
use std::slice;

View File

@ -48,6 +48,7 @@ impl<'lua> Debug<'lua> {
///
/// [Lua 5.1]: https://www.lua.org/manual/5.1/manual.html#pdf-LUA_HOOKTAILRET
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub fn event(&self) -> DebugEvent {
unsafe {
match (*self.ar.get()).event {
@ -131,6 +132,7 @@ impl<'lua> Debug<'lua> {
/// Corresponds to the `t` what mask. Returns true if the hook is in a function tail call, false
/// otherwise.
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub fn is_tail_call(&self) -> bool {
unsafe {
mlua_assert!(
@ -241,6 +243,7 @@ pub struct DebugStack {
/// Determines when a hook function will be called by Lua.
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
#[derive(Clone, Copy, Debug, Default)]
pub struct HookTriggers {
/// Before a function call.

View File

@ -72,7 +72,7 @@
//! [`serde::Deserialize`]: https://docs.serde.rs/serde/de/trait.Deserialize.html
// mlua types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/mlua/0.8.0-beta.1")]
#![doc(html_root_url = "https://docs.rs/mlua/0.8.0-beta.2")]
// Deny warnings inside doc tests / examples. When this isn't present, rustdoc doesn't show *any*
// warnings at all.
#![doc(test(attr(deny(warnings))))]
@ -124,7 +124,8 @@ pub use crate::value::{FromLua, FromLuaMulti, MultiValue, Nil, ToLua, ToLuaMulti
#[cfg(not(feature = "luau"))]
pub use crate::hook::HookTriggers;
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
pub use crate::chunk::Compiler;
#[cfg(feature = "async")]

View File

@ -810,6 +810,7 @@ impl Lua {
/// [`HookTriggers`]: crate::HookTriggers
/// [`HookTriggers.every_nth_instruction`]: crate::HookTriggers::every_nth_instruction
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub fn set_hook<F>(&self, triggers: HookTriggers, callback: F) -> Result<()>
where
F: 'static + MaybeSend + FnMut(&Lua, Debug) -> Result<()>,
@ -848,6 +849,7 @@ impl Lua {
/// Remove any hook previously set by `set_hook`. This function has no effect if a hook was not
/// previously set.
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub fn remove_hook(&self) {
// If main_state is not available, then sethook wasn't called.
let state = match self.main_state {
@ -982,7 +984,7 @@ impl Lua {
/// Returns true if the garbage collector is currently running automatically.
///
/// Requires `feature = "lua54/lua53/lua52"`
/// Requires `feature = "lua54/lua53/lua52/luau"`
#[cfg(any(
feature = "lua54",
feature = "lua53",
@ -1046,6 +1048,7 @@ impl Lua {
///
/// [lua_doc]: https://www.lua.org/manual/5.4/manual.html#2.5
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub fn gc_set_pause(&self, pause: c_int) -> c_int {
let state = self.main_state.unwrap_or(self.state);
unsafe { ffi::lua_gc(state, ffi::LUA_GCSETPAUSE, pause) }
@ -1069,6 +1072,7 @@ impl Lua {
///
/// [lua_doc]: https://www.lua.org/manual/5.4/manual.html#2.5.1
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub fn gc_inc(&self, pause: c_int, step_multiplier: c_int, step_size: c_int) -> GCMode {
let state = self.main_state.unwrap_or(self.state);

View File

@ -14,6 +14,7 @@ use crate::util::{assert_stack, check_stack, StackGuard};
use crate::value::Value;
/// Trait for serializing/deserializing Lua values using Serde.
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]
pub trait LuaSerdeExt<'lua> {
/// A special value (lightuserdata) to encode/decode optional (none) values.
///

View File

@ -8,7 +8,7 @@ pub struct StdLib(u32);
impl StdLib {
/// [`coroutine`](https://www.lua.org/manual/5.4/manual.html#6.2) library
///
/// Requires `feature = "lua54/lua53/lua52"`
/// Requires `feature = "lua54/lua53/lua52/luau"`
#[cfg(any(
feature = "lua54",
feature = "lua53",
@ -20,6 +20,7 @@ impl StdLib {
pub const TABLE: StdLib = StdLib(1 << 1);
/// [`io`](https://www.lua.org/manual/5.4/manual.html#6.8) library
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub const IO: StdLib = StdLib(1 << 2);
/// [`os`](https://www.lua.org/manual/5.4/manual.html#6.9) library
pub const OS: StdLib = StdLib(1 << 3);
@ -27,18 +28,19 @@ impl StdLib {
pub const STRING: StdLib = StdLib(1 << 4);
/// [`utf8`](https://www.lua.org/manual/5.4/manual.html#6.5) library
///
/// Requires `feature = "lua54/lua53"`
/// Requires `feature = "lua54/lua53/luau"`
#[cfg(any(feature = "lua54", feature = "lua53", feature = "luau"))]
pub const UTF8: StdLib = StdLib(1 << 5);
/// [`bit`](https://www.lua.org/manual/5.2/manual.html#6.7) library
///
/// Requires `feature = "lua52/luajit"`
/// Requires `feature = "lua52/luajit/luau"`
#[cfg(any(feature = "lua52", feature = "luajit", feature = "luau", doc))]
pub const BIT: StdLib = StdLib(1 << 6);
/// [`math`](https://www.lua.org/manual/5.4/manual.html#6.7) library
pub const MATH: StdLib = StdLib(1 << 7);
/// [`package`](https://www.lua.org/manual/5.4/manual.html#6.3) library
#[cfg(not(feature = "luau"))]
#[cfg_attr(docsrs, doc(cfg(not(feature = "luau"))))]
pub const PACKAGE: StdLib = StdLib(1 << 8);
/// [`jit`](http://luajit.org/ext_jit.html) library
///

View File

@ -352,6 +352,7 @@ impl<'lua> Table<'lua> {
///
/// Requires `feature = "luau"`
#[cfg(feature = "luau")]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
pub fn set_readonly(&self, enabled: bool) {
let lua = self.0.lua;
unsafe {
@ -363,6 +364,7 @@ impl<'lua> Table<'lua> {
///
/// Requires `feature = "luau"`
#[cfg(feature = "luau")]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
pub fn is_readonly(&self) -> bool {
let lua = self.0.lua;
unsafe { lua.ref_thread_exec(|refthr| ffi::lua_getreadonly(refthr, self.0.index) != 0) }

View File

@ -865,7 +865,6 @@ impl<'lua> AnyUserData<'lua> {
///
/// [`get_user_value`]: #method.get_user_value
/// [`set_nth_user_value`]: #method.set_nth_user_value
// #[cfg(not(feature = "luau"))]
#[inline]
pub fn set_user_value<V: ToLua<'lua>>(&self, v: V) -> Result<()> {
self.set_nth_user_value(1, v)
@ -877,7 +876,6 @@ impl<'lua> AnyUserData<'lua> {
///
/// [`set_user_value`]: #method.set_user_value
/// [`get_nth_user_value`]: #method.get_nth_user_value
// #[cfg(not(feature = "luau"))]
#[inline]
pub fn get_user_value<V: FromLua<'lua>>(&self) -> Result<V> {
self.get_nth_user_value(1)
@ -893,7 +891,6 @@ impl<'lua> AnyUserData<'lua> {
/// For other Lua versions this functionality is provided using a wrapping table.
///
/// [`get_nth_user_value`]: #method.get_nth_user_value
// #[cfg(not(feature = "luau"))]
pub fn set_nth_user_value<V: ToLua<'lua>>(&self, n: usize, v: V) -> Result<()> {
if n < 1 || n > u16::MAX as usize {
return Err(Error::RuntimeError(
@ -948,7 +945,6 @@ impl<'lua> AnyUserData<'lua> {
/// For other Lua versions this functionality is provided using a wrapping table.
///
/// [`set_nth_user_value`]: #method.set_nth_user_value
// #[cfg(not(feature = "luau"))]
pub fn get_nth_user_value<V: FromLua<'lua>>(&self, n: usize) -> Result<V> {
if n < 1 || n > u16::MAX as usize {
return Err(Error::RuntimeError(
@ -990,7 +986,6 @@ impl<'lua> AnyUserData<'lua> {
/// The value can be retrieved with [`get_named_user_value`].
///
/// [`get_named_user_value`]: #method.get_named_user_value
// #[cfg(not(feature = "luau"))]
pub fn set_named_user_value<S, V>(&self, name: &S, v: V) -> Result<()>
where
S: AsRef<[u8]> + ?Sized,
@ -1030,7 +1025,6 @@ impl<'lua> AnyUserData<'lua> {
/// Returns an associated value by name set by [`set_named_user_value`].
///
/// [`set_named_user_value`]: #method.set_named_user_value
// #[cfg(not(feature = "luau"))]
pub fn get_named_user_value<S, V>(&self, name: &S) -> Result<V>
where
S: AsRef<[u8]> + ?Sized,

View File

@ -35,7 +35,8 @@ pub enum Value<'lua> {
/// A floating point number.
Number(Number),
/// A Luau vector.
#[cfg(feature = "luau")]
#[cfg(any(feature = "luau", doc))]
#[cfg_attr(docsrs, doc(cfg(feature = "luau")))]
Vector(f32, f32, f32),
/// An interned string, managed by Lua.
///