Lua-API++  2015-02-12-3
Lua-API++ library
lua.hpp File Reference

Main include file for Lua API++ library (no other files need to be included). More...

Namespaces

 lua
 Every thing in Lua API++ library is contained inside this namespace.
 

Macros

#define LUAPP_USERDATA(type, class_name)   namespace lua { template <> struct UserData<type> {typedef void enabled; static constexpr const char* const classname = class_name;}; }
 Userdata type to name string binder. More...
 
#define LUAPP_ARG_CONVERT(src_type, body)   namespace lua { namespace _ { namespace wrap { template<> inline src_type argCvt<src_type>(const ::lua::Valref& val) body }}}
 Argument conversion binder. More...
 
#define LUAPP_RV_CONVERT(rv_type, body)   namespace lua { namespace _ { namespace wrap { template<> inline lua::Retval rvCvt<rv_type>(rv_type val, lua::Context& context) body }}}
 Return value conversion binder. More...
 

Typedefs

using LFunction = Retval(*)(Context &)
 Pointer to Lua API++ compatible function. More...
 

Functions

template<LFunction F>
int mkcf (lua_State *l)
 Wrapper for LFunction that creates a proper Lua-compatible C function. More...
 

Detailed Description

Main include file for Lua API++ library (no other files need to be included).

Macro Definition Documentation

#define LUAPP_USERDATA (   type,
  class_name 
)    namespace lua { template <> struct UserData<type> {typedef void enabled; static constexpr const char* const classname = class_name;}; }

Userdata type to name string binder.

Parameters
typeUserdata type being registered. Must be copyable or moveable.
class_nameString identifier.

Use this macro to register some type as a userdata type. After registration this type will be recognised as userdata and can be implicitly converted to Lua value and explicitly converted to from Lua value. The storage for the object is allocated by Lua.

Note
After registering userdata type with this macro, do not forget to assign its metatable during environment setup. For types that require destruction be sure to set __gc metamethod.
Use this macro outside of namespaces, functions, classes etc.
#define LUAPP_ARG_CONVERT (   src_type,
  body 
)    namespace lua { namespace _ { namespace wrap { template<> inline src_type argCvt<src_type>(const ::lua::Valref& val) body }}}

Argument conversion binder.

Parameters
src_typeNative type of function argument. Must not be supported native type or userdata.
bodyThe body of conversion function with curved braces.

This macro is used to define a conversion routine to transform Lua value into native value that will be used as an argument to a wrapped function passed to Context::wrap function.
Provide the type for the argument to be converted to from Lua value and the body for function receiving const Valref& val parameter and returning src_type. Example:

void arbitraryFunction(const std::vector<char>& x, int y);
LUAPP_ARG_CONVERT(std::vector<char>, {const char* arg = val; return std::vector<char>(arg, arg + strlen(arg));} )
Note
Use this macro outside of namespaces, functions, classes etc.
See also
lua::Context::wrap
#define LUAPP_RV_CONVERT (   rv_type,
  body 
)    namespace lua { namespace _ { namespace wrap { template<> inline lua::Retval rvCvt<rv_type>(rv_type val, lua::Context& context) body }}}

Return value conversion binder.

Parameters
rv_typeNative type of function argument. Must not be supported native type or userdata.
bodyThe body of conversion function with curved braces.

This macro is used to define a conversion routine to transform native value returned by arbitrary C++ function into a Lua value that will be returned by wrapper function created by Context::wrap function.
Provide the type for the return value to be converted to from Lua value and the body for function receiving arguments (rv_type&& val, lua::Context& context parameter. Example:

std::vector<char> otherArbitraryFunction();
LUAPP_RV_CONVERT(std::vector<char>, {return context.ret(val.data());}
Note
Use this macro outside of namespaces, functions, classes etc.
See also
lua::Context::wrap