From 143c3a81a7a648c1e7036190a8d3d0c656bd5c9f Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 30 Nov 2019 00:52:31 +0000 Subject: Add pair and ipair metamethods support (lua 5.2/5.3 only) --- src/userdata.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/userdata.rs') diff --git a/src/userdata.rs b/src/userdata.rs index 18da3b4..8177ad9 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -70,6 +70,16 @@ pub enum MetaMethod { /// /// This is not an operator, but will be called by methods such as `tostring` and `print`. ToString, + #[cfg(any(feature = "lua53", feature = "lua52"))] + /// The `__pairs` metamethod. + /// + /// This is not an operator, but it will be called by the built-in `pairs` function. + Pairs, + #[cfg(any(feature = "lua53", feature = "lua52"))] + /// The `__ipairs` metamethod. + /// + /// This is not an operator, but it will be called by the built-in `ipairs` function. + IPairs, } impl MetaMethod { @@ -105,6 +115,10 @@ impl MetaMethod { MetaMethod::NewIndex => b"__newindex", MetaMethod::Call => b"__call", MetaMethod::ToString => b"__tostring", + #[cfg(any(feature = "lua53", feature = "lua52"))] + MetaMethod::Pairs => b"__pairs", + #[cfg(any(feature = "lua53", feature = "lua52"))] + MetaMethod::IPairs => b"__ipairs", } } } -- cgit v1.2.3