浏览代码

Implement store size fn.

scossu 21 小时之前
父节点
当前提交
5c59ef1874
共有 1 个文件被更改,包括 16 次插入2 次删除
  1. 16 2
      src/lua_store.c

+ 16 - 2
src/lua_store.c

@@ -20,7 +20,9 @@ static int l_store_new (lua_State *L)
 }
 
 
-static int store_gc (lua_State *L)
+// This can be called automatically by te garbage collector, or manually.
+// It is idempotent.
+static int l_store_gc (lua_State *L)
 {
     VOLK_Store **sp = luaL_checkudata(L, 1, "VOLK.Store");
     LOG_DEBUG ("Garbage collecting store @%p.", *sp);
@@ -32,6 +34,15 @@ static int store_gc (lua_State *L)
 }
 
 
+static int l_store_size (lua_State *L)
+{
+    const VOLK_Store **store_p = luaL_checkudata (L, 1, "VOLK.Store");
+    lua_pushinteger (L, VOLK_store_size (*store_p));
+
+    return 1;
+}
+
+
 static int l_store_tostring (lua_State *L)
 {
     const VOLK_Store *store = *(VOLK_Store **) luaL_checkudata (
@@ -57,9 +68,12 @@ static const luaL_Reg store_lib_fn [] = {
 
 
 static const luaL_Reg store_lib_meth [] = {
-    {"__gc", store_gc},
+    {"__gc", l_store_gc},
+    {"__len", l_store_size},
     {"__tostring", l_store_tostring},
 
+    {"close", l_store_gc},
+
     {NULL}
 };