OOLua  2.0.1
C++ and Lua binding
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
First look

Hello Moon

void say(char const* input)
printf("%s from a standalone function\n", input);
OOLUA_CFUNC(say, l_say)
void hello_minimalist_function()
using namespace OOLUA; //NOLINT(build/namespaces)
Script vm;
set_global(vm, "say", l_say);
run_chunk(vm, "say('Hello Lua')");


  • DSL macros are upper case and prefixed with OOLUA_
  • Minimalist DSL macro names are shorter in length than Expressive names
  • Public API functions and types are directly in the OOLUA namespace
  • Public API function names are lower case with words separated by underscores

lua_State and Script

OOLua is purposely designed not to be dependent on the Script class and therefore passes around its dependency of a lua_State instance. The Script class is only a helper and anything you can do with it can be accomplished by using a Lua_function struct, calling OOLUA namespaced functions or using the Lua C API.

Script provides :

This class is not copy constructible or assignable. To accomplish this a counted reference to the lua_State would need to be maintained.
If you do not want to or can not use this class please see setup_user_lua_state

OOLua and the Lua stack

Lua's C API does not force you to treat the stack as such a data structure, with operations on just one end, instead for convenience it uses indices to identify stack slots for a procedure. Given that Lua is a C library, without C++'s name mangling and overloading, it also provides a function per type for pushing to the stack. Contrary to this, OOLua is a C++ library and it tries to enforce a clean stack after operations. The library therefore provides a simpler interface to the Lua stack which consists of two functions :

  • push Pushes an instance to top of the Lua stack.
  • pull Pulls the top element off the stack and pops it.

Most usage of OOLua will only require these two functions to interact with the stack. However, you are free to use Lua C API calls if you take into account that pull removes the top element from the stack when it is valid.

Library header files

OOLua provides a kitchen sink header file called oolua.h. This is a header which pulls in all the required files for using any part of the library. The file has the benefit that it maybe a good candidate for a pre compiled header, depending on the project in which it is to be used. However, a consequence of its functionality means that files which may not be required will always be pulled into files which include the header. If this is not the behaviour your project requires then there are two further headers for the proxying and exporting of classes. These files being oolua_dsl.h and oolua_dsl_export.h which are used extensively in the libraries unit tests.