[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Lua C Functions in C++ class
- From: "Kevin Baca" <lualist@...>
- Date: Tue, 21 Oct 2003 11:58:37 -0700
Check this out: http://lua-users.org/wiki/SimplerCppBinding
> I have a C++ class that exports some functions to a Lua environment.
> These functions are, of course, static, but they need to
> access member
> functions/variables of the class. The only way to do this (that I can
> think of) is to make those class members static as well, because
> there's no way to associate any sort of user data with the exported
> functions -- they only receive the lua_State* parameter, so I can't
> tell them which class they belong to when they're called.
> This wouldn't
> be such a problem, except that it's possible I might want multiple
> instances of this class at once, and clearly if they're both
> manipulating the same static members, there'll be problems,
> since these
> members really shouldn't be static.
> I can't think of a great way to solve this problem that
> doesn't involve
> jumping through hoops every time a function of the class gets called.
> Is there a design pattern I'm missing here? What do other
> people do in
> this situation?