Luwra
Minimal-overhead Lua wrapper for C++
|
Namespaces | |
namespace | internal |
Classes | |
struct | Function |
A callable Lua value. More... | |
struct | Function< void > |
A callable Lua value without a return value. More... | |
struct | Pushable |
Arbitrary pushable value. More... | |
struct | Reference |
Handle for a reference. More... | |
struct | RefLifecycle |
Lifecycle of a reference. More... | |
struct | ReturnValue |
A version of Value for pushing return values onto the stack. ReturnValue inherits push implementations from Value . More... | |
struct | ReturnValue< const Type > |
Alias for ReturnValue<Type> More... | |
struct | ReturnValue< const volatile Type > |
Alias for ReturnValue<Type> More... | |
struct | ReturnValue< std::pair< First, Second > > |
Enables std::pair as return type. More... | |
struct | ReturnValue< std::tuple< Contents... > > |
Enables std::tuple as return type. More... | |
struct | ReturnValue< Type & > |
Alias for ReturnValue<Type> More... | |
struct | ReturnValue< Type && > |
Alias for ReturnValue<Type> More... | |
struct | ReturnValue< volatile Type > |
Alias for ReturnValue<Type> More... | |
struct | StateWrapper |
Wrapper for a Lua state. More... | |
struct | Table |
Allows you to inspect and modify Lua tables. More... | |
struct | Value |
Enables reading/pushing for an arbitrary type. More... | |
struct | Value< bool > |
Enables reading/pushing booleans. More... | |
struct | Value< CFunction > |
Enables pushing for C functions. More... | |
struct | Value< char * > |
Alias for Value<const char*> More... | |
struct | Value< char[N]> |
Alias for Value<const char*> More... | |
struct | Value< const char * > |
Enables reading/pushing strings as C strings. More... | |
struct | Value< const char[N]> |
Alias for Value<const char*> More... | |
struct | Value< const Type > |
Alias for Value<Type> More... | |
struct | Value< const void * > |
Enables reading constant light data. More... | |
struct | Value< const volatile Type > |
Alias for Value<Type> More... | |
struct | Value< double > |
struct | Value< float > |
struct | Value< Function< Ret > > |
Enables reading/pushing Lua functions. More... | |
struct | Value< internal::InferValueType > |
Enables reading of type-infered values. More... | |
struct | Value< internal::Path< Parent, Key > > |
struct | Value< internal::TableAccessor< Accessor > > |
struct | Value< long double > |
struct | Value< LuaType > |
Enables reading the type of a value. More... | |
struct | Value< Pushable > |
Enables pushing for Pushables More... | |
struct | Value< Reference > |
Enables referencing/dereferencing values. More... | |
struct | Value< RefLifecycle > |
struct | Value< signed char > |
struct | Value< signed int > |
struct | Value< signed long int > |
struct | Value< signed long long int > |
struct | Value< signed short > |
struct | Value< State * > |
Enables reading Lua threads. More... | |
struct | Value< std::function< Ret(Args...)> > |
Enables reading Lua functions as std::function More... | |
struct | Value< std::list< Type > > |
Enables pushing for std::list assuming Type is pushable. More... | |
struct | Value< std::map< Key, Type > > |
Enables pushing and reading for std::map assuming Key and Type are pushable or readable. More... | |
struct | Value< std::nullptr_t > |
Enables reading/pushing nil More... | |
struct | Value< std::string > |
Enables reading/pushing string as std::string . More... | |
struct | Value< std::vector< Type > > |
Enables pushing for std::vector assuming Type is also pushable. More... | |
struct | Value< Table > |
Enables reading/pushing tables. More... | |
struct | Value< Type & > |
Alias for Value<Type> More... | |
struct | Value< Type && > |
Alias for Value<Type> More... | |
struct | Value< unsigned char > |
struct | Value< unsigned int > |
struct | Value< unsigned long int > |
struct | Value< unsigned long long int > |
struct | Value< unsigned short > |
struct | Value< UserType * > |
Enables reading and pushing the arbitrary type UserType . More... | |
struct | Value< void * > |
Enables reading/pushing light data. More... | |
struct | Value< volatile Type > |
Alias for Value<Type> More... | |
Typedefs | |
using | CFunction = lua_CFunction |
using | Integer = lua_Integer |
using | MemberMap = std::map< Pushable, Pushable > |
Allows mixed-type map of members. | |
using | Number = lua_Number |
using | State = lua_State |
Enumerations | |
enum class | LuaType { Nil = LUA_TNIL , Number = LUA_TNUMBER , Boolean = LUA_TBOOLEAN , String = LUA_TSTRING , Table = LUA_TTABLE , Function = LUA_TFUNCTION , Userdata = LUA_TUSERDATA , LightUserdata = LUA_TLIGHTUSERDATA , Thread = LUA_TTHREAD } |
Indicates the type of a Lua value. More... | |
Functions | |
template<typename Callable , typename... ExtraArgs> | |
internal::ReturnTypeOf< Callable > | apply (State *state, int pos, Callable &&func, ExtraArgs &&... args) |
Retrieve values from the stack in order to invoke a Callable with them. | |
template<typename UserType , typename... Args> | |
UserType & | construct (State *state, Args &&... args) |
Construct a user type value on the stack. | |
template<typename Iterable > | |
bool | equal (State *state, const Iterable &indices) |
Check if 0 or more values are equal. | |
bool | equal (State *state, int index1, int index2) |
Check if two values are equal. | |
template<typename Type , typename Key > | |
Type | getField (State *state, int index, Key &&key) |
Retrieve a field from a table. | |
template<typename Type > | |
Type | getGlobal (State *state, const char *name) |
Retrieve a value from the global namespace. | |
template<typename Callable , typename... ExtraArgs> | |
size_t | map (State *state, int pos, Callable &&func, ExtraArgs &&... args) |
Retrieve values from the stack in order to invoke a Callable with them, then push the result onto the stack. | |
template<typename... Types> | |
void | push (State *state, Types &&... values) |
Push zero or more values onto the stack. | |
template<typename... Types> | |
size_t | pushReturn (State *state, Types &&... values) |
Push zero or more return values onto the stack. | |
template<typename Type = internal::InferValueType> | |
auto | read (State *state, int index) -> decltype(Value< Type >::read(state, index)) |
Read a value off the stack. | |
template<typename Sig > | |
void | registerUserType (State *state, const char *ctor_name, const MemberMap &props=MemberMap(), const MemberMap &meta=MemberMap()) |
Same as the other registerUserType but registers a constructor in the global namespace. | |
template<typename UserType > | |
void | registerUserType (State *state, const MemberMap &props=MemberMap(), const MemberMap &meta=MemberMap()) |
Register the metatable for a user type. This function allows you to register properties which are shared across all instances of the user type. | |
void | setFields (State *state, int index, const MemberMap &fields) |
Apply key-value pairs to a table. | |
template<typename Key , typename Type > | |
void | setFields (State *state, int index, Key &&key, Type &&value) |
Set the field of a table. | |
template<typename Key1 , typename Type1 , typename Key2 , typename Type2 , typename... Pairs> | |
void | setFields (State *state, int index, Key1 &&key1, Type1 &&value1, Key2 &&key2, Type2 &&value2, Pairs &&... rest) |
Set multiple fields at once. Allows you to provide multiple key-value pairs. | |
template<typename Type > | |
void | setGlobal (State *state, const char *name, Type &&value) |
Register a value in the global namespace. | |
void | setMetatable (State *state, const char *name) |
Set a registered metatable for the table on top of the stack. | |
using luwra::CFunction = typedef lua_CFunction |
using luwra::Integer = typedef lua_Integer |
using luwra::MemberMap = typedef std::map<Pushable, Pushable> |
Allows mixed-type map of members.
Example:
using luwra::Number = typedef lua_Number |
using luwra::State = typedef lua_State |
|
strong |
|
inline |
Retrieve values from the stack in order to invoke a Callable
with them.
state | Lua state |
pos | Index of the first stack value |
func | A Callable |
args | Extra arguments passed to func before the stack values |
func
Invoke func
with args...
followed by the values retrieved from the stack.
Example 1:
Example 2:
|
inline |
Construct a user type value on the stack.
UserType | Type which you would like to construct |
state | Lua state |
args | Constructor arguments |
Creates a full userdata which holds an instance of the user type. A metatable that is specific to UserType
will be attached to the userdata. You can manage the metatable with registerUserType<UserType>.
Example:
|
inline |
Check if 0 or more values are equal.
state | Lua state |
indices | Indices of values to compare |
|
inline |
Check if two values are equal.
state | Lua state |
index1 | Index of left-hand side value |
index2 | Index of right-hand side value |
|
inline |
Retrieve a field from a table.
Type | Expected type of the value |
state | Lua state |
index | Index of the table |
key | Key value |
|
inline |
Retrieve a value from the global namespace.
Type | Expected type of the value |
state | Lua state |
name | Global name |
|
inline |
Retrieve values from the stack in order to invoke a Callable
with them, then push the result onto the stack.
state | Lua state |
pos | Index of the first stack value |
func | A Callable |
args | Extra arguments passed to func before the stack values |
Works similar to apply. This function pushes the result of func
onto the stack.
|
inline |
Push zero or more values onto the stack.
state | Lua state |
values | Values to push |
|
inline |
Push zero or more return values onto the stack.
state | Lua state |
values | Values to push |
|
inline |
Read a value off the stack.
Type | Type of targeted value |
state | Lua state |
index | Position of the value on the stack |
|
inline |
Same as the other registerUserType but registers a constructor in the global namespace.
Sig | A signature in the form of UserType(CtorArgs...) where UserType is the user type for which you would like to register the metatable and CtorArgs... the parameter types of the constructor. |
state | Lua state |
ctor_name | Constructor name |
props | Properties |
meta | Meta methods |
|
inline |
Register the metatable for a user type. This function allows you to register properties which are shared across all instances of the user type.
UserType | Type for which the metatable will be registered |
state | Lua state |
props | Properties of the user type |
meta | Meta methods of the user type |
By default, a garbage-collector hook and string representation function are added as meta methods. Both can be overwritten.
Example:
in Lua
Apply key-value pairs to a table.
state | Lua state |
index | Table index |
fields | Table fields |
|
inline |
Set the field of a table.
state | Lua state |
index | Index of the table |
key | Key |
value | Value |
|
inline |
Set multiple fields at once. Allows you to provide multiple key-value pairs.
state | Lua state |
index | Index of the table |
key1 | First key |
value1 | First value |
key2 | Second key |
value2 | Second value |
rest | Rest of the key-value pairs |
|
inline |
Register a value in the global namespace.
state | Lua state |
name | Global name |
value | Global value |
|
inline |
Set a registered metatable for the table on top of the stack.
state | Lua state |
name | Metatable name |