Exemple #1
0
/*
 * cursor,err = gridfs:list([lua_table or json_str])
 */
static int gridfs_list(lua_State *L) {
    GridFS *gridfs = userdata_to_gridfs(L, 1);

    BSONObj query;
    int type = lua_type(L, 2);
    if (type == LUA_TSTRING) {
        const char *jsonstr = luaL_checkstring(L, 2);
        query = fromjson(jsonstr);
    } else if (type == LUA_TTABLE) {
        lua_to_bson(L, 2, query);
    }
    std::auto_ptr<DBClientCursor> autocursor = gridfs->list(query);

    if (!autocursor.get()){
        lua_pushnil(L);
        lua_pushstring(L, LUAMONGO_ERR_CONNECTION_LOST);
        return 2;
    }

    DBClientCursor **cursor = (DBClientCursor **)lua_newuserdata(L, sizeof(DBClientCursor *));
    *cursor = autocursor.get();
    autocursor.release();

    luaL_getmetatable(L, LUAMONGO_CURSOR);
    lua_setmetatable(L, -2);

    return 1;
}
Exemple #2
0
/*
 * cursor,err = gridfs:list()
 */
static int gridfs_list(lua_State *L) {
    GridFS *gridfs = userdata_to_gridfs(L, 1);

    std::auto_ptr<DBClientCursor> autocursor = gridfs->list();

    if (!autocursor.get()) {
        lua_pushnil(L);
        lua_pushstring(L, LUAMONGO_ERR_CONNECTION_LOST);
        return 2;
    }

    DBClientCursor **cursor = (DBClientCursor **)lua_newuserdata(L, sizeof(DBClientCursor *));
    *cursor = autocursor.get();
    autocursor.release();

    luaL_getmetatable(L, LUAMONGO_CURSOR);
    lua_setmetatable(L, -2);

    return 1;
}