lua-users home
lua-l archive

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


I've written a thin C++ wrapper for the 4.0b API and thought I would share
my design notes as a starting point for anyone else.  Also on top of this
wrapper I made a "Lua Context" (not described below) that presents a class
interface of the Lua API and has a reference-counted Lua state.  By
subclassing from a Context you can easily work with the API without needing
to specifying state in each call.  Contexts are lightweight and may be
passed around and shared freely.  I've also found it useful to wrap Lua
callbacks so that any member function of a Context can be registered as a
Lua function, allowing a group of Lua functions to live inside a class and
share data and methods.

-John

----

// The C++ Lua interface is contained in a namespace "Lua".
//
    .
    .
    .
//
// Wrap macro constants (assigning to real const-qualified variables)
//
// SUMMARY OF DIFFERENCES FROM C API
//      * "LUA_" prefix removed
//
    .
    .
    .
//
// Wrap types (via typedef)
//
// SUMMARY OF DIFFERENCES FROM C API
//      * "lua_" prefix removed
//
    .
    .
    .
//
// Wrap functions and macro functions (via inlining)
//
// SUMMARY OF DIFFERENCES FROM C API
//      * "lua_" prefix removed
//      * integers with boolean meaning changed to bool type
//      * register renamed to registercfunction (register is a C keyword)
//      * State argument qualified as const where there is no
//          user-observable change to state
//      * pushlstring renamed to pushstring (overloading)
//      * pushcclosure removed
//      * pushcfunction and registercfunction take optional closure count
//      * open has default stacksize=0
//      * pop has default n=1
//      * concat has default n=2
//      * index defaults to stack top in the following functions:
//          pushvalue, type, is*, to*, next, getn
//      * equal and lessthan have defaults i1="top-1", i2="top".  (RPN
//          ordering.)