From 241690fe5733e758166d8fcd52acaa5f2e505cb0 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 21 Mar 2023 16:38:07 +0000 Subject: add lmdb.pairs() for iteration on lua versions without __pairs metamethod also fix minor formatting error in readme --- README.md | 6 +++--- lmdb.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8187d3..b4db243 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ read the value of `key` from the database. ### `db[key] = value` write `value` as the value of `key` into the database. -### `pairs(db)` -returns `lmdb.next, db, nil`. +### `pairs(db)`, `lmdb.pairs(db)` +returns `lmdb.next, db, nil`, allowing iteration through all the key-value pairs of a database. the `lmdb.pairs` form works even on lua 5.1, which doesn't support the `__pairs` metamethod. -## `#db` +### `#db` return the number of entries in the database. diff --git a/lmdb.c b/lmdb.c index 03c696f..a1c4e8e 100644 --- a/lmdb.c +++ b/lmdb.c @@ -361,6 +361,7 @@ static const struct luaL_Reg lmdb[] = { {"open", env_open}, {"version", version}, {"next", db_next}, + {"pairs",db_pairs}, {NULL, NULL}, }; -- cgit v1.2.3