[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Looking for a better way with Lua, C++, and static members
- From: Jules Bean <jules@...>
- Date: Fri, 15 Aug 2003 13:26:22 +0100
On Fri, Aug 15, 2003 at 02:19:34AM -0700, Eric Wing wrote:
> Hi, thank you for the response. I'm still kind of new
> to Lua so if you could provide me a little source code
> example, I would appreciate it.
Your problem seems to be a C++ problem not a lua problem.
> variable called font_size. Because my functions are
> static, my variable is forced to be static.
Well yes. Do you want your functions to be static or not?
> class ConversationGameMode
> static int MakeChoice(lua_State* ls);
> static int SetFontSize(lua_State* ls);
> // This is what I would like to do but can't
> // int font_size;
> // This is what I end up doing
> static int font_size;
So do this:
static int MakeChoice(lua_State* ls);
static int SetFontSize(lua_State* ls);
static int font_size;
> In this example, I would like a way to encapsulate
> font_size so it isn't a static (or global) variable.
Static variables can be hidden inside classes, as I showed.
> These methods didn't really need to be embedded in a
> class, but it just kind of worked out that way when I
> started trying to encapsulate things, not knowing at
> the time that I had to declare things as static.
> However, even as regular C/C++ functions, I still
> don't know how to make font_size accessable without
> making it static or global.
Well, there's global scope or file scope.
Or you can have static local variables in your functions. This
probably isn't what you want, though.