Exemplo n.º 1
0
// Fetches a context by index.
Context* GetContext(int index)
{
	ContextMap::iterator i = contexts.begin();
	int count = 0;

	if (index >= GetNumContexts())
		index = GetNumContexts() - 1;

	while (count < index)
	{
		++i;
		++count;
	}

	if (i == contexts.end())
		return NULL;

	return (*i).second;
}
Exemplo n.º 2
0
//[1] is the object, [2] is the last used key, [3] is the userdata
int RocketContextsProxy__ipairs(lua_State* L)
{
    RocketContextsProxy* obj = LuaType<RocketContextsProxy>::check(L,1);
    LUACHECKOBJ(obj);
    int* pindex = (int*)lua_touserdata(L,3);
    if((*pindex) == -1)
        *pindex = 0;
    Context* value = NULL;
    if((*pindex)++ < GetNumContexts())
    {
        value = GetContext(*pindex);
    }
    if(value == NULL)
    {
        lua_pushnil(L);
        lua_pushnil(L);
    }
    else
    {
        lua_pushinteger(L,(*pindex)-1);
        LuaType<Context>::push(L,value);
    }
    return 2;
}