lua-users home
lua-l archive

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


Both the replies have worked fine, thanks. But I suddenly realised that I had another problem. By default variables in Lua are global right? so if the users don't explicitly define their variables as local ones they'll be around for the execution of the next user script. Then I saw that there was a table were the globals are kept in the index LUA_GLOBALSINDEX. Can I made a copy of this table before execute and then after replace it by the copy I made before right? The thing is that I print lua_objlen(pLuaState,LUA_GLOBALSINDEX) (it should print the number of globals or at least a number other than zero right?) and it prints zero. Is this the correct behaviour? Another thing, how can I copy the table to specified index? lua_pushvalue(L, LUA_GLOBALSINDEX) copy it to the top of the stack how can I move it to position COPY_GLOBALSINDEX?

thanks,
José Tavares

On 1/21/07, Zé Pedro <zarroba@gmail.com> wrote:
I've seen a similar question already answered in the list but I'm not sure it applies to my problem.
In my program I'm executing lua code made by users and I have no control over it. What I'm doing now is setting the variables the code needs by doing:
                     lua_pushinteger(pLuaState, (int)atoi(value.c_str()));
                     lua_setglobal(pLuaState, name.c_str());

and then executing the script doing:
                     luaL_dostring (pLuaState, script.c_str())

the thing is that the script has no functions or anything, just calls to methods and declaration of variables. Once a script is executed the variables should be cleared but this must be made in C after the luaL_dostring call. Is there any way to do this or do I have to create a new LuaState for each time I execute a script?

thanks,
José Tavares

--
Believe nothing, no matter where you read it, or who said it,
no matter if I have said it, unless it agrees with your own reason
and your common sense.
- Buda

Para quê ter olhos azuis, se a Natureza deixa os meus  vermelhos?
- Bob Marley

"Don't try to use what you learn from Buddhism to be a Buddhist;
use it to be a better whatever-you-already-are."
- His Holiness the 14th Dalai Lama

Idealism is what precedes experience; cynicism is what follows.
  - David T. Wolf

"Please don't download, because I want to get a pool in my second home."
  - Kanye West



--
Believe nothing, no matter where you read it, or who said it,
no matter if I have said it, unless it agrees with your own reason
and your common sense.
- Buda

Para quê ter olhos azuis, se a Natureza deixa os meus  vermelhos?
- Bob Marley

"Don't try to use what you learn from Buddhism to be a Buddhist;
use it to be a better whatever-you-already-are."
- His Holiness the 14th Dalai Lama

Idealism is what precedes experience; cynicism is what follows.
  - David T. Wolf

"Please don't download, because I want to get a pool in my second home."
  - Kanye West