lua-users home
lua-l archive

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


I prefer to use toLua for this purpose. toLua will generate some c code
that, when linked with your app, will allow you to directly access objects
of type foo - all of their methods and (public) members.

More about toLua is available here:
http://www.tecgraf.puc-rio.br/~celes/tolua/

If you're interested, I've also written a tool that I've integrated into my
build process that generates a toLua package file from your C++ header file,
feeds the result into toLua, and links in the result automatically. I can
send it to you if you're interested.

Eric

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Curt Carpenter
> Sent: Monday, July 09, 2001 2:26 PM
> To: Multiple recipients of list
> Subject: RE: binding C++ member functions to lua
>
>
> Start by reading the docs. They're not that long. You cannot do directly
> what you are trying to do, i.e. share a C++ member variable.
>
> You can accomplish what you want to do in one of two ways. In either
> way, you will probably have a corresponding Lua table for each C++ class
> instance. Then, either:
> 1) Lua owns the data, and C reads it when it needs it. That is, your C++
> class contains enough information to get to the corresponding Lua table,
> and reads from there in the Get* methods, and sets the values in the
> Set* methods. This optimizes for the case where most of the
> reading/writing of the variables takes place in script.
> 2) Opposite of 1. C owns the data and Lua invokes tag methods to
> read/write the data on demand from/to C. This method optimizes for when
> the variables are used mostly within C.
>
> At least those are the obvious choices. Maybe someone else has done
> something more elegant?
>
> -----Original Message-----
> From: jtrichter@hotmail.com [mailto:jtrichter@hotmail.com]
> Sent: Monday, July 09, 2001 2:18 PM
> To: Multiple recipients of list
> Subject: binding C++ member functions to lua
>
>
> I am pretty new to lua and I need my lua scripts to be able to access
> class variables and/or member functions.  I am working on Win2K and
> using VC++.
>
> Here is a basic example:
> ---------------------------------------------------
> class foo
> {
> public:
> 	foo(char* startName, int startCash);
> 	int x;
> 	char* y;
> 	int getX();
> 	int setX();
> };
>
> I want to register foo::setX() so my script can easily change the
> data within the class.
>
> or
>
> I want to directly change variable "x" from a lua script
> ----------------------------------------------------
>
> Can anyone help with this, please?