lua-users home
lua-l archive

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


Hi,

As I've used Lua over the years, I've always written a C++ wrapper to 
simplify my life.  It is extremely lightweight, but it does do some 
useful functionality that is otherwise obscure.

The archive may be found at 
http://workspacewhiz.com/Other/Script/Script_LuaWrapper.zip.

The documentation (what little there is) is at 
http://workspacewhiz.com/Other/Script/Docs/index.html.  The 
documentation was made through Doxygen (see the Links page of 
http://workspacewhiz.com/).

The wrapper is a class called Script.  What does Script do that is 
special, besides providing a halfway object oriented approach to Lua?

* A nested class Script::Object represents an object on the Lua 
stack.  Encapsulates the stack index of the given object.  (You can 
refer to Lua objects by their C variable name, not by index.)
* Script::Object contains the parent script, making it possible to 
pass Script::Object objects to functions and retrieve the script, if 
necessary.
* Script::Object provides a method of creating a named table through 
a single function, CreateTable().
* Simple methods for setting a number, string, or user data into the 
current Script::Object.
* Two methods in Script::Object for finding a particular table 
element: GetByName() and GetByIndex() (for arrays).
* A nested class Script::AutoBlock represents a way of automatically 
restoring the stack state when AutoBlock falls out of scope.  
(Helpful for not leaving extraneous stuff on the stack.)
* Provides a Lua function, CopyTable(), that does a deep copy of a 
table.
* .ini file-like configuration function, Script::ConfigGet*() and 
Script::ConfigSet*().
* Script::SaveText() dumps out the current Lua state to a file.  
Originally modeled after the Lua test program.  Has been reworked to 
format everything in a "pretty" fashion.

The archive above contains a copy of the Lua source, the Script 
class, some test code, and Visual C++ projects.  The code should be 
portable to other compilers.

Lua has been a great tool to work with, and in some cases, a life 
saver.  Thanks go to the authors for such a great product.

Thanks,
Joshua Jensen
Author, Workspace Whiz! - A Visual Studio Add-in
Author, Script (A Lua Wrapper)
http://workspacewhiz.com/