[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Local variables in the main block are global
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sun, 21 Apr 2013 09:39:19 +0200
2013/4/21 Dirk Laurie <dirk.laurie@gmail.com>:
> Sorry, hit the sent button too soon. The behaviour of the
> title occurs in a long module of mine, and I am still trying
> to isolate it. It's not that simple. Sorry!
Turns out I have been too clever for my own good.
My module loads another module written in C. That module has a tiny bit
of initialization code in Lua. I use a global variable also called
'X' in there; I delete it immediately, but the bug detector picks it up.
The C file ends something like this:
~~~
char *mymodule_init =
"for k,v in pairs(_G) do X[k]=v end "
"X=nil"
;
LUAMOD_API int luaopen_mymodule_core (lua_State *L) {
luaL_newlib(L, myfuncs);
lua_pushvalue(L,-1); lua_setglobal(L,"X");
(void)luaL_dostring(L,mymodule_init);
return 1;
}
~~~
Actually, I have not been clever at all. Global variables with one-letter
names are hazardous even in initializion code in a C module, The bug
detector in my original accidental post does exactly what it should.