lua-users home
lua-l archive

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


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
> {
> public:
>     static int MakeChoice(lua_State* ls);
>     static int SetFontSize(lua_State* ls);
> 
> private:
>     // 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:

class ConversationGameMode
{
public:
    static int MakeChoice(lua_State* ls);
    static int SetFontSize(lua_State* ls);

private:
    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.

Jules