[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Modifying table in index tag function
- From: "J. Perkins" <jason@...>
- Date: Tue, 29 May 2001 22:53:02 -0400
I have an index tag function that does a bunch of disk-intensive work
(searches for
and loads DLLs and scripts). I want it to run only if the item being
indexed doesn't
already exist in the table. So within my tag method, rather than just
returning the
new item back to the caller, I also explicitly add it to the table.
Something like this:
int indexTagFunction(lua_State* L)
{
// get name of the requested table element
const char* componentName = lua_tostring(L, 2);
// ...do some work to create the Lua table which represents the
component.
// When I'm done it is left on the top of the stack.
// Add the component to the master table
int ref = lua_ref(L, 0);
lua_pushstring(L, componentName);
lua_getref(L, ref);
lua_settable(L, 1);
// ...at this point I can dump the contents of the table and I will
see my
// component listed there as (string)"name" = (userdata)component
// Return the new component back to the caller
lua_getref(L, ref);
return 1;
}
So when this function exits, the component is in the master table. However,
when I try to retrieve the value from the master table, the index tag
function
gets called again, and the master table is empty...the component that I
added
has disappeared. I'm a little baffled as to why this is happening. Does the
tag method get a copy of the table, rather than the original, or what is
happening here?
Jason
379