[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: How catch new globals?
- From: "J. Perkins" <starkos@...>
- Date: Fri, 28 Oct 2005 17:03:44 -0400
This is my first foray back into Lua since the 4.0 days...quite a bit
has changed I see. I am porting some old code to Lua 5 and I'm stuck
trying to replace a "getglobal" tag method.
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.
I'm sure this is easy, but I couldn't seem to come up with the right
Google words to find an answer. Perhaps it is so basic and obvious
that no one else needed to ask :p
Thanks for the help,
Jason