[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: First post: Hierarchal Data storage... - Changing vars in tab les from C
- From: Dave Owens <DaveO@...>
- Date: Mon, 29 Sep 2003 17:04:44 +0100
Hi yall..me again..
I cant get my head around this stack useage, so I'm afraid I'm asking out
again..
I use this generic function to traverse my tables, to put onto the top of
the stack, the variable requested
bool FindChunk(const char *Name)
{
lua_getfenv(mLuaVM,0);
while (*Name)
{
int Type=lua_type(mLuaVM,-1);
if (Type!=LUA_TTABLE)
{ // Check we are currently looking at a table.
return(false);
}
int Len=0;
while (Name[Len] && Name[Len]!='.')
{
Len++;
}
lua_pushlstring(mLuaVM, Name, Len);
lua_gettable(mLuaVM, -2);
lua_remove(mLuaVM, -2); // Keep Stack tidy
Name+=Len;
if (*Name)
{
Name++;
}
}
return(lua_type(mLuaVM,-1)!=LUA_TNIL);
}
Now, this function works fine, but when I try to do the flow for changing a
variable, i.e.
if (FindChunk(BaseBucket,Name))
{
int Type=lua_type(mLuaVM,-1);
ASSERTM(Type==LUA_TNUMBER,"Var Not Number");
lua_pushnumber(mLuaVM,v);
lua_settable(mLuaVM, -2);
return(true);
}
Whatever value I put in the settable for stack pos, either bombs, or does
nothing..
What am I thick at now?
-----Original Message-----
From: Dave Owens [mailto:DaveO@climax.co.uk]
Sent: 26 September 2003 11:37
To: Lua list
Subject: RE: First post: Hierarchal Data storage...
Once again..thanks...
Last one (maybe) for the moment..
I don't like having to have a 'named' table to hold all my 'tables' i.e.
Config = {
blah = {
...
..
}
}
In that I need to do
>> lua_getglobal(mLuaVM, "Config"); <<
lua_pushlstring(mLuaVM, Name, Len);
lua_gettable(mLuaVM, -2);
Using my new ref thingy, Id like to create a base table, that the script
vars are loaded into..how do I do that? And what are the limits for Refs? Do
I have to free them?
-----Original Message-----
From: Ashwin Hirschi [mailto:deery@chello.nl]
Sent: 26 September 2003 03:32
To: Lua list
Subject: Re: First post: Hierarchal Data storage...
> Is it possible to store off the current 'table address' held in the
> stack, so I can quickly push it back later?
You can use:
- lua_ref to get an int reference to your table
- lua_getref to push your ref'd table back on the stack, and
- lua_unref to release the reference
This'll work in both Lua 4 and 5.
Ashwin.