Skip to content

Commit eb76db5

Browse files
committed
Make userdata module public
1 parent 33bf3ff commit eb76db5

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ mod stdlib;
8585
mod thread;
8686
mod traits;
8787
mod types;
88-
mod userdata;
8988
mod util;
9089
mod value;
9190
mod vector;
@@ -95,6 +94,7 @@ pub mod function;
9594
pub mod prelude;
9695
pub mod string;
9796
pub mod table;
97+
pub mod userdata;
9898

9999
pub use bstr::BString;
100100
pub use ffi::{self, lua_CFunction, lua_State};
@@ -116,14 +116,17 @@ pub use crate::types::{
116116
AppDataRef, AppDataRefMut, Either, Integer, LightUserData, MaybeSend, MaybeSync, Number, RegistryKey,
117117
VmState,
118118
};
119-
pub use crate::userdata::{
120-
AnyUserData, MetaMethod, UserData, UserDataFields, UserDataMetatable, UserDataMethods, UserDataRef,
121-
UserDataRefMut, UserDataRegistry,
122-
};
119+
pub use crate::userdata::AnyUserData;
123120
pub use crate::value::{Nil, Value};
124121

122+
// Re-export some types to keep backward compatibility and avoid breaking changes in the public API.
125123
#[doc(hidden)]
126124
pub use crate::string::LuaString as String;
125+
#[doc(hidden)]
126+
pub use crate::userdata::{
127+
MetaMethod, UserData, UserDataFields, UserDataMetatable, UserDataMethods, UserDataRef, UserDataRefMut,
128+
UserDataRegistry,
129+
};
127130

128131
#[cfg(not(feature = "luau"))]
129132
pub use crate::debug::HookTriggers;

src/userdata.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
//! Lua userdata handling.
2+
//!
3+
//! This module provides types for creating and working with Lua userdata from Rust.
4+
//!
5+
//! # Main Types
6+
//!
7+
//! - [`AnyUserData`] - A handle to a Lua userdata value of any Rust type.
8+
//! - [`UserData`] - Trait to implement for types that should be exposed to Lua as userdata.
9+
//! - [`UserDataFields`] - Trait for registering fields on userdata types.
10+
//! - [`UserDataMethods`] - Trait for registering methods on userdata types.
11+
//! - [`UserDataRegistry`] - Registry for userdata methods and fields.
12+
//! - [`UserDataMetatable`] - A handle to the metatable of a userdata type.
13+
//! - [`UserDataRef`] - A borrowed reference to a userdata value.
14+
//! - [`UserDataRefMut`] - A mutably borrowed reference to a userdata value.
15+
//! - [`MetaMethod`] - Metamethod names for customizing Lua operators.
16+
117
use std::any::TypeId;
218
use std::ffi::CStr;
319
use std::fmt;

tests/userdata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ fn test_userdata_namecall() -> Result<()> {
13761376
struct MyUserData;
13771377

13781378
impl UserData for MyUserData {
1379-
fn register(registry: &mut mlua::UserDataRegistry<Self>) {
1379+
fn register(registry: &mut UserDataRegistry<Self>) {
13801380
registry.add_method("method", |_, _, ()| Ok("method called"));
13811381
registry.add_field_method_get("field", |_, _| Ok("field value"));
13821382

0 commit comments

Comments
 (0)