nngn
Loading...
Searching...
No Matches
nngn::lua Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  alloc_info
 Tracks state allocations. More...
 
class  defer_pop
 Pops n values from the Lua stack at scope exit. More...
 
struct  error
 "Pushing" this value causes lua_error to be called. More...
 
struct  function_value
 Owning reference to a function on the stack. More...
 
struct  function_view
 Non-owning reference to a function on the stack. More...
 
class  global_table
 Table interface to the global environment. More...
 
struct  nil_type
 Used to push nil values onto the stack. More...
 
struct  stack_get
 Reads a value from the Lua stack. More...
 
struct  stack_get< bool >
 Converts a value to boolean using Lua's rules (i.e. More...
 
struct  stack_get< const char * >
 Reads a C string value. More...
 
struct  stack_get< const lua_vector< T > & >
 
struct  stack_get< lua_CFunction >
 Reads a lua_CFunction value. More...
 
struct  stack_get< lua_vector< T > * >
 
struct  stack_get< pos >
 
struct  stack_get< state_view >
 
struct  stack_get< std::optional< T > >
 Reads a T if a value exists at that index (no type check is performed). More...
 
struct  stack_get< std::string >
 Reads a string value as ptr+size. More...
 
struct  stack_get< std::string_view >
 Reads a string value as ptr+size. More...
 
struct  stack_get< std::tuple< Ts... > >
 Reads a sequence of values from the stack. More...
 
struct  stack_get< std::vector< T > >
 Reads a table array as a vector. More...
 
struct  stack_get< T & >
 Reads a user type as a full user data value (reference overload). More...
 
struct  stack_get< T * >
 Reads a light user data value as void*. More...
 
struct  stack_get< T >
 Reads a value convertible to lua_Integer. More...
 
struct  stack_push
 Pushes a value onto the Lua stack. More...
 
struct  stack_push< bool >
 Pushes a value as a Lua boolean. More...
 
struct  stack_push< const char * >
 Pushes a C string value. More...
 
struct  stack_push< error< T > >
 Emits an error. More...
 
struct  stack_push< lua_CFunction >
 Pushes a lua_CFunction value. More...
 
struct  stack_push< lua_vector< T > >
 
struct  stack_push< nil_type >
 Pushes a Lua nil value. More...
 
struct  stack_push< R(*)(Args...)>
 Pushes a function pointer. More...
 
struct  stack_push< R(T::*)(Args...) const >
 Same as the previous specialization, but for const member functions. More...
 
struct  stack_push< R(T::*)(Args...)>
 Same as the previous specialization, but for member functions. More...
 
struct  stack_push< std::optional< T > >
 Pushes a T if the object contains a value, otherwise nothing. More...
 
struct  stack_push< std::string >
 Convenience specialization for the std::string_view overload. More...
 
struct  stack_push< std::string_view >
 Pushes a ptr+size string value. More...
 
struct  stack_push< std::tuple< Ts... > >
 Pushes a sequence of values onto the stack. More...
 
struct  stack_push< std::variant< Ts... > >
 Pushes the active member of the variant. More...
 
struct  stack_push< T & >
 Pushes a user type as a full user data value (reference specialization). More...
 
struct  stack_push< T * >
 Pushes a generic pointer as a light user data value. More...
 
struct  stack_push< T >
 Pushes a value convertible to lua_Integer. More...
 
struct  stack_push< table_proxy< T, Ks... > >
 
struct  stack_push< void >
 Generic version of stack_push, deduces type from the argument. More...
 
struct  state
 Owning lua_State wrapper. More...
 
class  state_view
 
class  static_register
 Registers a function to be executed when the Lua state is initialized. More...
 
struct  table
 Owning reference to a table on the stack, popped when destroyed. More...
 
class  table_proxy
 Expression template for table assignemnts. More...
 
struct  table_view
 Non-owning reference to a table on the stack. More...
 
class  traceback
 Type used to output the Lua call stack. More...
 
class  user_data
 Data block allocated for user data objects. More...
 
struct  user_data< T >
 
struct  user_data_header
 Header placed before a user data allocation. More...
 
struct  value
 Owning stack value reference. More...
 
class  value_view
 Base, non-owning generic stack value reference. More...
 

Concepts

concept  user_type
 
concept  stack_ref
 

Enumerations

enum class  type : int {
  X , none = LUA_TNONE , nil = LUA_TNIL , boolean = LUA_TBOOLEAN ,
  light_user_data = LUA_TLIGHTUSERDATA , number = LUA_TNUMBER , string = LUA_TSTRING , table = LUA_TTABLE ,
  function = LUA_TFUNCTION , user_data = LUA_TUSERDATA , thread = LUA_TTHREAD , X ,
  none = LUA_TNONE , nil = LUA_TNIL , boolean = LUA_TBOOLEAN , light_user_data = LUA_TLIGHTUSERDATA ,
  number = LUA_TNUMBER , string = LUA_TSTRING , table = LUA_TTABLE , function = LUA_TFUNCTION ,
  user_data = LUA_TUSERDATA , thread = LUA_TTHREAD
}
 LUA_T* constants as a scoped enumeration. More...
 
enum class  type : int {
  X , none = LUA_TNONE , nil = LUA_TNIL , boolean = LUA_TBOOLEAN ,
  light_user_data = LUA_TLIGHTUSERDATA , number = LUA_TNUMBER , string = LUA_TSTRING , table = LUA_TTABLE ,
  function = LUA_TFUNCTION , user_data = LUA_TUSERDATA , thread = LUA_TTHREAD , X ,
  none = LUA_TNONE , nil = LUA_TNIL , boolean = LUA_TBOOLEAN , light_user_data = LUA_TLIGHTUSERDATA ,
  number = LUA_TNUMBER , string = LUA_TSTRING , table = LUA_TTABLE , function = LUA_TFUNCTION ,
  user_data = LUA_TUSERDATA , thread = LUA_TTHREAD
}
 LUA_T* constants as a scoped enumeration. More...
 

Functions

template<typename R , typename ... Args>
call (lua_State *L, R(*f)(Args...), int i)
 Calls the regular function f with arguments taken from the stack.
 
template<typename R , typename T , typename ... Args>
call (lua_State *L, R(T::*f)(Args...), int i)
 Calls member function f with object/arguments taken from the stack.
 
template<stateless_lambda T>
 call (lua_State *L, T, int i)
 Calls a stateless lambda.
 
template<typename T >
auto ipairs (const T &table)
 Simple wrapper for a table value, returns ipairs-style iterators.
 
int msgh (lua_State *L)
 Default message handler for lua_pcall.
 
void print_stack (lua_State *L)
 Logs the current data stack.
 
void print_traceback (lua_State *L)
 Logs the current call stack.
 
template<typename T >
 error (T) -> error< T >
 
constexpr type type_from_lua (int t)
 Maps LUA_T* values to type.
 
std::string_view type_str (type t)
 
template<member_pointer auto p>
int accessor (lua_State *L)
 Lua function template which pushes an object's member.
 
template<member_pointer auto p>
int value_accessor (lua_State *L)
 Similar to nngn::lua::accessor, but returns the member by value.
 
template<typename T >
T get (nngn::lua::state_view L, int i)
 
template<typename T = value_view>
T push (nngn::lua::state_view lua, auto &&v)
 
template<typename T , typename PT , typename ... Ks>
 operator== (T &&lhs, const table_proxy< PT, Ks... > &rhs)
 
template<typename T , typename PT , typename ... Ks>
 operator== (const table_proxy< PT, Ks... > &lhs, T &&rhs)
 
table table_array (state_view lua, auto &&...args)
 Creates a table array with each argument in succession.
 
template<std::ranges::range T>
table table_from_range (state_view lua, T &&r)
 Creates a table array from a range.
 
table table_map (state_view lua, auto &&...args)
 Creates a table with each successive argument pair as key/value.
 
std::ostream & operator<< (std::ostream &os, const traceback &t)
 
auto defer_settop (lua_State *L, int i=-1)
 Resets the top of the stack at scope exit.
 
auto stack_mark (lua_State *L, int extra=0)
 Creates a scoped object which verifies the stack top at scope exit.
 
template<typename T >
bool operator== (T &&lhs, const value_view &rhs)
 
template<typename T >
bool operator== (const value_view &lhs, T &&rhs)
 

Variables

constexpr struct nngn::lua::nil_type nil
 
constexpr std::array types
 type values as a sequential array.
 
template<typename T >
constexpr auto is_user_type = false
 Flag which indicates that a type is to be treated as a user type.
 
template<typename T >
constexpr empty metatable_name = {}
 Key in the global table where the meta-table for T is stored.
 
template<typename T >
constexpr bool is_stack_ref = false
 Determines whether a type is a reference to a value on the stack.
 
template<typename T >
requires ( std::derived_from<T, detail::table_base_tag> && !std::derived_from<T, value> && !std::same_as<T, global_table>)
constexpr bool is_stack_ref< T > = true
 
template<typename T >
constexpr auto user_data_header_align
 

Enumeration Type Documentation

◆ type [1/2]

enum class nngn::lua::type : int
strong

LUA_T* constants as a scoped enumeration.

Enumerator
none 
nil 
boolean 
light_user_data 
number 
string 
table 
function 
user_data 
thread 
none 
nil 
boolean 
light_user_data 
number 
string 
table 
function 
user_data 
thread 

◆ type [2/2]

enum class nngn::lua::type : int
strong

LUA_T* constants as a scoped enumeration.

Enumerator
none 
nil 
boolean 
light_user_data 
number 
string 
table 
function 
user_data 
thread 
none 
nil 
boolean 
light_user_data 
number 
string 
table 
function 
user_data 
thread 

Function Documentation

◆ accessor()

template<member_pointer auto p>
int nngn::lua::accessor ( lua_State *  L)

Lua function template which pushes an object's member.

Receives a user data value of the containing type and returns a pointer to the member.

◆ call() [1/3]

template<typename R , typename ... Args>
R nngn::lua::call ( lua_State *  L,
R(*)(Args...)  f,
int  i 
)

Calls the regular function f with arguments taken from the stack.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ call() [2/3]

template<typename R , typename T , typename ... Args>
R nngn::lua::call ( lua_State *  L,
R(T::*)(Args...)  f,
int  i 
)

Calls member function f with object/arguments taken from the stack.

Calls member function, const overload.

Here is the call graph for this function:

◆ call() [3/3]

template<stateless_lambda T>
nngn::lua::call ( lua_State *  L,
T  ,
int  i 
)

Calls a stateless lambda.

Here is the call graph for this function:

◆ defer_settop()

auto nngn::lua::defer_settop ( lua_State *  L,
int  i = -1 
)
inline

Resets the top of the stack at scope exit.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error()

template<typename T >
nngn::lua::error ( T  ) -> error< T >
Here is the call graph for this function:

◆ get()

template<typename T >
T nngn::lua::get ( nngn::lua::state_view  L,
int  i 
)

◆ ipairs()

template<typename T >
auto nngn::lua::ipairs ( const T table)

Simple wrapper for a table value, returns ipairs-style iterators.

Intended to be used directly in a range for expressions to modify the implicit begin/end calls, e.g.:

for(auto [i, x] : ipairs(t))
use(i, x);
for i
Definition: font.lua:5
auto ipairs(const T &table)
Simple wrapper for a table value, returns ipairs-style iterators.
Definition: iter.h:227

Since it is a function, most uses can omit the namespace qualification and use the name directly due to ADL.

Here is the call graph for this function:

◆ msgh()

int nngn::lua::msgh ( lua_State *  L)

Default message handler for lua_pcall.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<()

std::ostream & nngn::lua::operator<< ( std::ostream &  os,
const traceback t 
)

◆ operator==() [1/4]

template<typename T , typename PT , typename ... Ks>
nngn::lua::operator== ( const table_proxy< PT, Ks... > &  lhs,
T &&  rhs 
)

◆ operator==() [2/4]

template<typename T >
bool nngn::lua::operator== ( const value_view lhs,
T &&  rhs 
)
Here is the call graph for this function:

◆ operator==() [3/4]

template<typename T , typename PT , typename ... Ks>
nngn::lua::operator== ( T &&  lhs,
const table_proxy< PT, Ks... > &  rhs 
)

◆ operator==() [4/4]

template<typename T >
bool nngn::lua::operator== ( T &&  lhs,
const value_view rhs 
)
Here is the call graph for this function:

◆ print_stack()

void nngn::lua::print_stack ( lua_State *  L)

Logs the current data stack.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_traceback()

void nngn::lua::print_traceback ( lua_State *  L)

Logs the current call stack.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push()

template<typename T = value_view>
T nngn::lua::push ( nngn::lua::state_view  lua,
auto &&  v 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stack_mark()

auto nngn::lua::stack_mark ( lua_State *  L,
int  extra = 0 
)
inline

Creates a scoped object which verifies the stack top at scope exit.

At the end of the object's scope, a message is logged if the current top of the stack is different than orig + extra, where orig is the top at the time of the stack_mark call.

See also
nngn::scoped
Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_array()

table nngn::lua::table_array ( state_view  lua,
auto &&...  args 
)

Creates a table array with each argument in succession.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_from_range()

template<std::ranges::range T>
table nngn::lua::table_from_range ( state_view  lua,
T &&  r 
)

Creates a table array from a range.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ table_map()

table nngn::lua::table_map ( state_view  lua,
auto &&...  args 
)

Creates a table with each successive argument pair as key/value.

I.e {[args[0]] = args[1], [args[2]] = args[3], ...}.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ type_from_lua()

constexpr type nngn::lua::type_from_lua ( int  t)
inlineconstexpr

Maps LUA_T* values to type.

Here is the caller graph for this function:

◆ type_str()

std::string_view nngn::lua::type_str ( type  t)
inline
Here is the caller graph for this function:

◆ value_accessor()

template<member_pointer auto p>
int nngn::lua::value_accessor ( lua_State *  L)

Similar to nngn::lua::accessor, but returns the member by value.

Variable Documentation

◆ is_stack_ref

template<typename T >
constexpr bool nngn::lua::is_stack_ref< std::optional< T > > = false
inlineconstexpr

Determines whether a type is a reference to a value on the stack.

These will be left on the stack after they are retrieved from a table. Specializations can be added for user-provided types.

◆ is_stack_ref< T >

template<typename T >
requires ( std::derived_from<T, detail::table_base_tag> && !std::derived_from<T, value> && !std::same_as<T, global_table>)
constexpr bool nngn::lua::is_stack_ref< T > = true
inlineconstexpr

◆ is_user_type

template<typename T >
constexpr auto nngn::lua::is_user_type = false
inlineconstexpr

Flag which indicates that a type is to be treated as a user type.

Specializations should be added (see NNGN_LUA_DECLARE_USER_TYPE) to indicate that values of this type should be read from / pushed onto the stack as Lua full user data values.

◆ metatable_name

template<typename T >
constexpr empty nngn::lua::metatable_name = {}
inlineconstexpr

Key in the global table where the meta-table for T is stored.

Actual type is fixed_string, empty is used to make the unspecialized value invalid.

See also
NNGN_LUA_DECLARE_USER_TYPE

◆ nil

constexpr struct nngn::lua::nil_type nngn::lua::nil

◆ types

constexpr std::array nngn::lua::types
inlineconstexpr
Initial value:
= [] {
using U = std::underlying_type_t<type>;
constexpr auto f = to_underlying<type>;
constexpr auto b = f(type::none), e = f(type::thread) + 1;
constexpr auto n = e - b;
std::array<U, n> u = {};
std::array<type, n> ret = {};
std::iota(begin(u), end(u), b);
std::transform(
std::ranges::begin(u), std::ranges::end(u),
std::ranges::begin(ret), to<type>{});
return ret;
}()
function DEMO text end
Definition: demo0.lua:6
n
Definition: dump_lights.lua:5
function f()) end
e
Definition: math.lua:4
constexpr const R * begin(const T< R > &v)
Definition: vec.h:207
Function object which converts its argument to T via static_cast.
Definition: fn.h:25

type values as a sequential array.

◆ user_data_header_align

template<typename T >
constexpr auto nngn::lua::user_data_header_align
inlineconstexpr
Initial value:
=
std::max(alignof(T), alignof(T*))
#define T(f0, f1, f2)