aboutsummaryrefslogtreecommitdiff
path: root/lmdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'lmdb.c')
-rw-r--r--lmdb.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lmdb.c b/lmdb.c
index 60ddca2..03c696f 100644
--- a/lmdb.c
+++ b/lmdb.c
@@ -288,6 +288,19 @@ static int db_put(lua_State *L) {
return 0;
}
+static int db_len(lua_State *L) {
+ lua_settop(L, 1);
+ MDB_dbi dbi = *(MDB_dbi *) luaL_checkudata(L, 1, "lmdb.db");
+ check_env(L, 1);
+
+ get_parent(L, 1);
+ struct handle *tud = lua_touserdata(L, -1);
+ struct MDB_stat stat;
+ asserr(mdb_stat(tud->obj, dbi, &stat));
+ lua_pushinteger(L, stat.ms_entries);
+ return 1;
+}
+
static int db_next(lua_State *L) {
lua_settop(L, 2);
MDB_dbi dbi = *(MDB_dbi *) luaL_checkudata(L, 1, "lmdb.db");
@@ -377,6 +390,7 @@ static const struct luaL_Reg lmdb_db[] = {
{"__index", db_get},
{"__newindex", db_put},
{"__pairs", db_pairs},
+ {"__len", db_len},
{NULL, NULL},
};