lua-users home
lua-l archive

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


It was thus said that the Great meino.cramer@gmx.de once stated:
> Hi,
> 
> Is there anything in lua like what is available in C:
> 
>     static int counter:
> 
> (where "int" and "counter" are examples to satisfy the
> syntax and are not part of the question...;)

  In what context?  Because "static" has meaning depending upon where it
appears.

	static int counter;	/* 1 */
	
	static int foo(void)	/* 2 */
	{
	  static int bar;	/* 3 */
	}

1.	counter has file scope---it's only visible to the file its defined
	in, and can't be seen by other compilation units (files).  Its
	symbol does not appear in the resulting object or executable file
	[1].

2.	This is identical to 1, except for a function, not a variable.

3.	In this context, "static" means "persistent storage."  The variable
	"bar", only visible in function foo(), exists for the lifetime of
	the program, not the function, and thus, its contents will remain
	across multiple calls to foo().

  -spc

[1]	With the possible exception of a special "debug" mode for the
	comiler/linker, but that's system dependent.