nngn
Loading...
Searching...
No Matches
nngn::lua::state_view Class Reference

#include <state.h>

Inheritance diagram for nngn::lua::state_view:

Public Member Functions

 state_view (void)=default
 Empty state, must call init before any other function is called.
 
 state_view (lua_State *L_)
 Wraps an existing luaState.
 
 operator lua_State * (void) const
 Implicit conversion so the state can be passed to Lua functions.
 
bool init (alloc_info *i=nullptr)
 Initializes a new state.
 
state_view release (void)
 
void destroy (void)
 Destroys the associated lua_State.
 
int top (void) const
 
type get_type (int i) const
 
template<typename T = lua_Integer>
T len (int i) const
 
std::pair< lua_Alloc, void * > allocator (void) const
 Get memory allocator data.
 
global_table globals (void) const
 
void set_top (int i) const
 
void set_meta_table (auto &&mt, int i)
 
void print_stack (void) const
 Non-static version.
 
void print_traceback (void) const
 Non-static version.
 
bool doarg (std::string_view s) const
 Calls dofile or dostring depending on s[0] == '@'.
 
bool dofile (std::string_view filename) const
 
bool dostring (std::string_view src) const
 
bool dofunction (std::string_view f) const
 Executes the global function f.
 
template<typename T >
Tnew_user_data (int nv=0) const
 
template<typename T >
table new_user_type (void) const
 Registers a new user type and returns its meta table.
 
table create_table (void) const
 Creates a table and pushes it on the stack.
 
table create_table (int narr, int nrec) const
 Creates a table and pushes it on the stack.
 
template<typename T = value_view>
T get (int i) const
 Reads a value from the stack.
 
template<typename T = value_view>
T push (auto &&x) const
 Pushes a value onto the stack.
 
void pop (int n=1) const
 
void remove (int i) const
 
void call (auto &&f, auto &&...args) const
 Function call, protected in debug mode.
 
int pcall (auto &&h, auto &&f, auto &&...args) const
 Protected function call with error handler.
 
std::pair< value, std::string_view > to_string (int i) const
 Pushes a string representation of a value onto the stack.
 
bool heartbeat (void) const
 Execute the global heartbeat function.
 

Protected Attributes

lua_State * L = nullptr
 

Constructor & Destructor Documentation

◆ state_view() [1/2]

nngn::lua::state_view::state_view ( void )
default

Empty state, must call init before any other function is called.

◆ state_view() [2/2]

nngn::lua::state_view::state_view ( lua_State * L_)
inline

Wraps an existing luaState.

Member Function Documentation

◆ allocator()

std::pair< lua_Alloc, void * > nngn::lua::state_view::allocator ( void ) const
inline

Get memory allocator data.

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

◆ call()

void nngn::lua::state_view::call ( auto && f,
auto &&... args ) const

Function call, protected in debug mode.

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

◆ create_table() [1/2]

table nngn::lua::state_view::create_table ( int narr,
int nrec ) const
inline

Creates a table and pushes it on the stack.

◆ create_table() [2/2]

table nngn::lua::state_view::create_table ( void ) const
inline

Creates a table and pushes it on the stack.

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

◆ destroy()

void nngn::lua::state_view::destroy ( void )

Destroys the associated lua_State.

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

◆ doarg()

bool nngn::lua::state_view::doarg ( std::string_view s) const

Calls dofile or dostring depending on s[0] == '@'.

See how the lua interpreter program handles LUA_INIT.

Here is the call graph for this function:

◆ dofile()

bool nngn::lua::state_view::dofile ( std::string_view filename) const
See also
luaL_dofile
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dofunction()

bool nngn::lua::state_view::dofunction ( std::string_view f) const

Executes the global function f.

Here is the call graph for this function:

◆ dostring()

bool nngn::lua::state_view::dostring ( std::string_view src) const
See also
luaL_dostring
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

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

Reads a value from the stack.

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

◆ get_type()

type nngn::lua::state_view::get_type ( int i) const
inline
See also
lua_type
Here is the call graph for this function:
Here is the caller graph for this function:

◆ globals()

global_table nngn::lua::state_view::globals ( void ) const
inline
See also
nngn::lua::global_table
Here is the caller graph for this function:

◆ heartbeat()

bool nngn::lua::state_view::heartbeat ( void ) const

Execute the global heartbeat function.

Here is the call graph for this function:

◆ init()

bool nngn::lua::state_view::init ( alloc_info * i = nullptr)

Initializes a new state.

The current state, if it exists, is destroyed.

Parameters
iIf set, track all allocations (if compiled with custom allocator support).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ len()

template<typename T >
T nngn::lua::state_view::len ( int i) const
See also
lua_len
Here is the call graph for this function:
Here is the caller graph for this function:

◆ new_user_data()

template<typename T >
T * nngn::lua::state_view::new_user_data ( int nv = 0) const
See also
lua_newuserdatauv
Here is the call graph for this function:

◆ new_user_type()

template<typename T >
table nngn::lua::state_view::new_user_type ( void ) const

Registers a new user type and returns its meta table.

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

◆ operator lua_State *()

nngn::lua::state_view::operator lua_State * ( void ) const
inline

Implicit conversion so the state can be passed to Lua functions.

◆ pcall()

int nngn::lua::state_view::pcall ( auto && h,
auto && f,
auto &&... args ) const

Protected function call with error handler.

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

◆ pop()

void nngn::lua::state_view::pop ( int n = 1) const
inline
See also
lua_pop
Here is the caller graph for this function:

◆ print_stack()

void nngn::lua::state_view::print_stack ( void ) const
inline

Non-static version.

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

◆ print_traceback()

void nngn::lua::state_view::print_traceback ( void ) const
inline

Non-static version.

Here is the call graph for this function:

◆ push()

template<typename T >
T nngn::lua::state_view::push ( auto && x) const

Pushes a value onto the stack.

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

◆ release()

state_view nngn::lua::state_view::release ( void )
inline
Here is the caller graph for this function:

◆ remove()

void nngn::lua::state_view::remove ( int i) const
inline
See also
lua_remove
Here is the caller graph for this function:

◆ set_meta_table()

void nngn::lua::state_view::set_meta_table ( auto && mt,
int i )
See also
lua_setmetatable
Here is the call graph for this function:

◆ set_top()

void nngn::lua::state_view::set_top ( int i) const
inline
See also
lua_settop

◆ to_string()

std::pair< value, std::string_view > nngn::lua::state_view::to_string ( int i) const
inline

Pushes a string representation of a value onto the stack.

Here is the caller graph for this function:

◆ top()

int nngn::lua::state_view::top ( void ) const
inline
See also
lua_gettop
Here is the caller graph for this function:

Member Data Documentation

◆ L

lua_State* nngn::lua::state_view::L = nullptr
protected

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