[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How catch new globals?
- From: "J. Perkins" <starkos@...>
- Date: Mon, 31 Oct 2005 11:27:25 -0500
On 10/28/05, Tomas <tomas@ccpa.puc-rio.br> wrote:
> > lua_pushstring(L, "newindex");
> Have you tried "__newindex"?
Yes. As I mentioned in my original post, I tried "newindex",
"__newindex", as well as "index" and "__index". My function is never
called.
So I don't lose the context, here is the important bits of my original
post are below. Maybe this isn't as easy as I thought it would be.
Jason
My 4.0 code looked like this:
lua_pushcfunction(L, getglobal);
lua_settagmethod(L, LUA_TNIL, "getglobal");
For 5.0 I tried to do this:
lua_pushvalue(L, LUA_GLOBALSINDEX);
lua_getmetatable(L, -1);
lua_pushstring(L, "__newindex");
lua_pushcfunction(L, getglobal);
lua_settable(L, -3)
But my function never gets called. I also tried "index", "__newindex",
and "__index", but no avail.
FYI, what I am trying to do is catch statements of the form:
package.name = "MyPackage"
...where `package` hasn't been defined yet. My function will create a
table, populate a few values, and then setglobal("package") before
returning.