nngn
Loading...
Searching...
No Matches
nngn::lua::user_data< T > Class Template Reference

Data block allocated for user data objects. More...

#include <user.h>

Inheritance diagram for nngn::lua::user_data< T >:
Collaboration diagram for nngn::lua::user_data< T >:

Public Types

using get_type = std::remove_pointer_t<T>*
 

Public Member Functions

 user_data (const T &x)
 Creates a non-owning (reference) object.
 
 user_data (T &&x)
 Creates an owning (copy) object.
 
get_type get (void) const
 Pointer to the contained/referenced object.
 
void destroy (void)
 Destroys the T value if this is an owning user data value.
 

Static Public Member Functions

static get_type get (state_view lua, int i)
 Retrieves a user data of type T from the stack.
 
static get_type from_light (const void *p)
 Retrieves a user data of type T from a light user data value.
 
static bool check_type (state_view lua, int i)
 Verifies that the value on the stack is a user data of type T.
 
static table push_metatable (state_view lua)
 Pushes the type's meta table onto the stack.
 
static int gc (lua_State *L)
 Function to be used as a user data's __gc meta-method.
 
static int eq (lua_State *L)
 Function to be used as a user data's __eq meta-method.
 
template<typename R >
static int push (state_view lua, R &&r)
 Pushes a value on the stack as a user data of type T.
 

Private Types

using header_type = user_data_header<T>
 
using base_type = typename alloc_block<header_type, T>::storage
 
- Private Types inherited from nngn::alloc_block< H, T >::storage
using parent = alloc_block
 

Static Private Member Functions

static get_type get_pointer (state_view lua, int i)
 
- Static Private Member Functions inherited from nngn::lua::detail::user_data_base
static table push_metatable (state_view lua, std::string_view meta)
 Pushes the table stored as meta in the global table.
 
static bool check_type (state_view lua, int i, std::string_view meta)
 
static bool check_pointer_type (state_view lua, int i, std::string_view meta)
 

Static Private Attributes

static constexpr auto meta
 

Friends

class user_data< T * >
 

Additional Inherited Members

- Private Attributes inherited from nngn::alloc_block< H, T >::storage
header_type header = {}
 
value_type data = {}
 

Detailed Description

template<typename T>
class nngn::lua::user_data< T >

Data block allocated for user data objects.

This object is owning (i.e. must be destroyed / garbage collected) if header.p points to data. Otherwise,header.p points to an existing (external) object and no space is allocated for data.

Member Typedef Documentation

◆ base_type

template<typename T >
using nngn::lua::user_data< T >::base_type = typename alloc_block<header_type, T>::storage
private

◆ get_type

template<typename T >
using nngn::lua::user_data< T >::get_type = std::remove_pointer_t<T>*

◆ header_type

template<typename T >
using nngn::lua::user_data< T >::header_type = user_data_header<T>
private

Constructor & Destructor Documentation

◆ user_data() [1/2]

template<typename T >
nngn::lua::user_data< T >::user_data ( const T & x)
explicit

Creates a non-owning (reference) object.

◆ user_data() [2/2]

template<typename T >
nngn::lua::user_data< T >::user_data ( T && x)
explicit

Creates an owning (copy) object.

Member Function Documentation

◆ check_type()

template<typename T >
static bool nngn::lua::user_data< T >::check_type ( state_view lua,
int i )
static

Verifies that the value on the stack is a user data of type T.

◆ destroy()

template<typename T >
void nngn::lua::user_data< T >::destroy ( void )

Destroys the T value if this is an owning user data value.

This is done when the value was initially pushed as a value / rvalue reference type.

See also
push

◆ eq()

template<typename T >
static int nngn::lua::user_data< T >::eq ( lua_State * L)
static

Function to be used as a user data's __eq meta-method.

Compares objects by identity (i.e. address).

mt["__eq"] = &user_data<T>::eq;
Data block allocated for user data objects.
Definition user.h:73
local mt
Definition strict.lua:4

◆ from_light()

template<typename T >
static get_type nngn::lua::user_data< T >::from_light ( const void * p)
static

Retrieves a user data of type T from a light user data value.

No type verification is performed.

Parameters
pMust be a pointer to an object in the same format as what is pushed by push.
Here is the caller graph for this function:

◆ gc()

template<typename T >
static int nngn::lua::user_data< T >::gc ( lua_State * L)
static

Function to be used as a user data's __gc meta-method.

E.g.:

mt["__gc"] = &user_data<T>::gc;

◆ get() [1/2]

template<typename T >
static get_type nngn::lua::user_data< T >::get ( state_view lua,
int i )
static

Retrieves a user data of type T from the stack.

◆ get() [2/2]

template<typename T >
get_type nngn::lua::user_data< T >::get ( void ) const
inline

Pointer to the contained/referenced object.

Here is the caller graph for this function:

◆ get_pointer()

template<typename T >
static get_type nngn::lua::user_data< T >::get_pointer ( state_view lua,
int i )
staticprivate

◆ push()

template<typename T >
template<typename R >
static int nngn::lua::user_data< T >::push ( state_view lua,
R && r )
static

Pushes a value on the stack as a user data of type T.

R may be either a pointer, reference, or value type. For pointers and lvalue references, the user data is a reference to an existing value. For value or rvalue references, the user data is pushed as an independent copy of the value.

Here is the caller graph for this function:

◆ push_metatable()

template<typename T >
static table nngn::lua::user_data< T >::push_metatable ( state_view lua)
static

Pushes the type's meta table onto the stack.

Friends And Related Symbol Documentation

◆ user_data< T * >

template<typename T >
friend class user_data< T * >
friend

Member Data Documentation

◆ meta

template<typename T >
auto nngn::lua::user_data< T >::meta
staticconstexprprivate
Initial value:
=
std::remove_const_t<std::remove_pointer_t<T>>>
constexpr empty metatable_name
Key in the global table where the meta-table for T is stored.
Definition lua.h:156

The documentation for this class was generated from the following file: