Luwra
Minimal-overhead Lua wrapper for C++
Classes | Namespaces | Macros | Typedefs | Functions
usertypes.hpp File Reference

Classes

struct  luwra::internal::UserTypeWrapper< UserType >::ConstructorWrapper< Args >
 
struct  luwra::internal::UserTypeReg< UserType >
 
struct  luwra::internal::UserTypeWrapper< UserType >
 
struct  luwra::Value< UserType >
 Enables reading/pushing for an arbitrary type. More...
 
struct  luwra::Value< UserType * >
 Enables reading and pushing the arbitrary type UserType. More...
 

Namespaces

namespace  luwra
 
namespace  luwra::internal
 

Macros

#define LUWRA_DEF_REGISTRY_NAME(type, regname)
 Define the registry name for a user type. This macro has to be used outside of any namespace.
 
#define LUWRA_MEMBER(type, name)    {#name, LUWRA_WRAP_MEMBER(type, name)}
 Generate a user type member manifest. This is basically any type which can be constructed using a string and a lua_CFunction. For example std::pair<Pushable, Pushable>.
 
#define LUWRA_WRAP_CONSTRUCTOR(type, ...)    (&luwra::internal::UserTypeWrapper<type>::ConstructorWrapper<__VA_ARGS__>::invoke)
 Generate a lua_CFunction wrapper for a constructor.
 

Typedefs

template<typename UserType >
using luwra::internal::StripUserType = typename std::remove_cv< UserType >::type
 

Functions

template<typename UserType , typename... Args>
UserType & luwra::construct (State *state, Args &&... args)
 Construct a user type value on the stack.
 
template<typename Sig >
void luwra::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 luwra::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.
 

Macro Definition Documentation

◆ LUWRA_DEF_REGISTRY_NAME

#define LUWRA_DEF_REGISTRY_NAME (   type,
  regname 
)
Value:
LUWRA_NS_BEGIN \
namespace internal { \
template <> struct UserTypeReg<type> { static const std::string name; }; \
const std::string UserTypeReg<type>::name = (regname); \
} \

Define the registry name for a user type. This macro has to be used outside of any namespace.

Parameters
typeUser type
regnameRegistry name

◆ LUWRA_MEMBER

#define LUWRA_MEMBER (   type,
  name 
)     {#name, LUWRA_WRAP_MEMBER(type, name)}

Generate a user type member manifest. This is basically any type which can be constructed using a string and a lua_CFunction. For example std::pair<Pushable, Pushable>.

Parameters
typeUser type
nameMember name

Example:

struct A {
void foo();
};
// ...
// LUWRA_MEMBER(A, foo) == {"foo", LUWRA_WRAP_MEMBER(A, foo)}
MemberMap members {
LUWRA_MEMBER(A, foo)
};

◆ LUWRA_WRAP_CONSTRUCTOR

#define LUWRA_WRAP_CONSTRUCTOR (   type,
  ... 
)     (&luwra::internal::UserTypeWrapper<type>::ConstructorWrapper<__VA_ARGS__>::invoke)

Generate a lua_CFunction wrapper for a constructor.

Parameters
typeType to instantiate
...Constructor parameter types

Example:

struct A {
A(const char* a, int b);
};
// ...
lua_CFunction ctor = LUWRA_WRAP_CONSTRUCTOR(A, const char*, int);
setGlobal(state, "A", ctor);

in Lua

local a = A("Hello World", 11)