lua-users home
lua-l archive

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


For those who are accessing Lua from C++ code,
this may be of interest.

I have implemented a C++ API to access and manipulate Lua values.
It consists of a header file (lua++.h) that defines a few classes
that naturally bind Lua objects to C++ type and vice-versa. 

For instance, if we have the following Lua code:

myTable = {name = "lua++"}

It is valid to write a C++ code like this one:

 ...
 LuaObject t = Lua:getglobal("myTable");  // access the table object
 LuaObject f = Lua:getglobal("print");    // access the pre-defined function 
 f(t["name"]);       // call Lua function
 ...

which will output the string "lua++".

Also, if we have a Lua function:

function myFunc (a,b)
 print(a+b)
end

We can call it from C++ code doing:

 ...
 LuaObject f = Lua:getglobal("myFunc");
 f(5,7);
 ...

It is still a beta version, but if you want to try it
and help me to improve it, the code and a naive documentation
can be reached at:
http://www.graphics.cornell.edu/~celes/lua++/lua++.html


Waldemar

--------------
Waldemar Celes
Program of Computer Graphics
Cornell University
580 Engineering Theory Center Building
Ithaca, NY -- 14853
e-mail: celes@graphics.cornell.edu
home page: http://www.graphics.cornell.edu/~celes/