lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

I am glad to announce that I wrote a new interface to perform a
generic call to Lua in C++ [1].
The idea was already explained in "Programming in Lua" [2].
In 2007, I wrote a more complete version of call_va, called Lua
Generic Call, which I recently migrated onto GitHub [3].
And last month, a question about its implementation gave me the idea
to use C++ classes to do the same thing, but better :-)

This new implementation can only be used in C++, since it (overly)
uses constructor overloads, templates and pointer to member functions.
 It consists in a single header file where all functions are inline.

[1] https://github.com/prapin/LuaClassBasedCall
[2] http://www.lua.org/pil/25.3.html
[3] https://github.com/prapin/LuaGenericCall


The features described below are taken from the documentation:

*  Automatic Lua state creation and closing
*  Automatic C++ type handling for both input and output values
*  Lots of data types are already supported (see next paragraph)
*  Some types can specify an optional size to an explicit
   constructor, as a second argument
*  It is usually possible to add support for custom types externally
*  Code snippets can also be wide character strings
*  Various error handling possibilities:
   1. unprotected call
   2. protected call: the function returns the error message or NULL
   3. exception call: a C++ exception can be sent with the error message
*  Compiled code snippets are cached for performance
*  Error messages include the stack back trace
*  Some compilation switches can exclude unportable code or huge headers

C++ types currently handled
*  Special enumerated nil value
*  Boolean values
*  All types of numerical values
*  Regular const char* strings
*  Wide character strings, automatically converted to/from UTF-8
*  C functions having the signature lua_CFunction
*  Lua threads represented as lua_State*
*  Generic const void* pointers, mapped to light or full userdata
*  C arrays of any supported type: the number of elements must be
   passed to the explicit constructor as its first argument.
*  Some STL (Standard Template Library) classes (more to come):
   * string
   * wstring
   * vector<T>
   * map<K,T>
*  Some MFC (Microsoft Foundation Classes) elements:
   * CStringA
   * CStringW
   * CArray<T1,T2>