lua-users home
lua-l archive

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


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?