[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Global variables, and lua states
- From: Rici Lake <lua@...>
- Date: Mon, 30 May 2005 00:14:39 -0500
On 29-May-05, at 11:46 PM, Zulfiqar Malik wrote:
First of all, I want to know whether we can create multiple lua states
in one thread? I tried it and the second lua state that I created was
crashing whenever I tried to load a script with it!
Sure. Lua states (created by lua_open) are completely independent of
What you cannot do is try to move internal data from one to the other.
Secondly, I want to know the overhead associated with each lua state
in case you can create more than one in a thread? Because if I can
create multiple states in a thread, then the sort of thing I am
targeting right now, I could end up creating 100s of lua states, if
nothing else works.
There isn't much overhead, but it does take up some RAM. A hundred
states is reasonable if RAM is not precious. A thousand might be
Thirdly, isn’t there any way in which I can create variables, that are
global to a particular script and not for the whole lua state.
Something like static variables at global/function scope in C.
If you declare a variable local in a compiled chunk, then it is local
in that chunk. The fact that Lua implements proper closures makes such
variables work something like static variables (but better, since each
instance of the compiled chunk gets its own.)
I know I can use tables, but I would make it easier for the developer,
but not forcing him into using tables.
Any help shall be highly appreciated.
Zulfiqar Inayat Malik.