[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Using LUA for config files
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 13 Sep 2007 08:53:19 -0300
> The way I would like this to work is something like:
>
> lua_getglobal(pLuaState, "Enemy.Hitpoints");
Try this, which works for any depth:
static void mygetglobal(lua_State* L, const char* s) {
const char* limit = s + strlen(s);
lua_pushvalue(L, LUA_GLOBALSINDEX);
for (;;) {
const char* e = strchr(s, '.');
lua_pushlstring(L, s, (e ? e : limit) - s);
lua_gettable(L, -2);
lua_remove(L, -2);
if (e == NULL || lua_isnil(L, -1)) break;
s = e + 1;
}
}
(based on http://lua-users.org/lists/lua-l/2003-03/msg00081.html )