lua-users home
lua-l archive

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



> [mailto:owner-lua-l@tecgraf.puc-rio.br] On Behalf Of DoG
> Sent: January 20, 2003 10:02 AM
> To: Multiple recipients of list
> Subject: where to find lua and c++ examples
> 
> I would like to include lua into my project, which is mostly 
> written in 
> c++. I looked at luna, and it seems to be the easiest way to 
> start off. 
> I am working on a cross-platform project, but I am currently 
> developing 
> on MacOS X. So, after looking at the luna examples, and reading the 
> docs and lua technotes, I still don't quite understand how to pass 
> arguments to and from lua and how to handle multiple assignments. Any 
> pointers?


For an example of a project containing C++ and Lua, with bindings using
tolua (not Luna) you could look at http://doris.sf.net/ It should work
cross platform but noone has ever mailed me to verify this :-) There are
*nix makefiles which I believe should work in a Mac environment - Mac is
built on BSD isnt it?

For passing variables back and forth WebLua might be useful:
http://doris.sourceforge.net/lua/weblua.php
eg.

Lua script: (passing variables from C to Lua)

local t = {}
foo(1,t,3)

lua2c generates the following: 

static int MAIN(lua_State *L)
{
 lua_newtable(L);
 lua_getglobal(L,"foo");
 lua_pushnumber(L,1);
 lua_pushvalue(L,1);
 lua_pushnumber(L,3);
 lua_call(L,3,0);
 return 0;
}

Lua script: (multiple assignment?)

a,b,c = 1,2,3

lua2c generates the following: 

static int MAIN(lua_State *L)
{
 lua_pushnumber(L,1);
 lua_pushnumber(L,2);
 lua_pushnumber(L,3);
 lua_setglobal(L,"c");
 lua_setglobal(L,"b");
 lua_setglobal(L,"a");
 return 0;
}

If you look at Doris you'll see how to go the other way and pass
arguments from Lua to C. This is all Lua version 4 (the current official
version). Mmmm I should add a tolua button to weblua to generate code
from interfaces.

Regards,
Nick