Prechádzať zdrojové kódy

Term sets to tables; graph encoding.

scossu 5 dní pred
rodič
commit
0a19711d23
12 zmenil súbory, kde vykonal 390 pridanie a 335 odobranie
  1. 1 0
      .gitignore
  2. 5 5
      Makefile
  3. 2 2
      README.md
  4. 182 154
      src/lua_graph.c
  5. 12 12
      src/lua_namespace.c
  6. 16 16
      src/lua_store.c
  7. 111 86
      src/lua_term.c
  8. 33 33
      src/lua_triple.c
  9. 1 1
      src/lua_volksdata.c
  10. 14 14
      src/lua_volksdata.h
  11. 7 7
      test.lua
  12. 6 5
      volksdata-scm-1.rockspec

+ 1 - 0
.gitignore

@@ -42,5 +42,6 @@ luac.out
 vgcore*
 
 # Local
+.vimrc
 tmp/
 !.keep

+ 5 - 5
Makefile

@@ -1,12 +1,12 @@
 PREFIX ?= /usr/local
 
-INCLUDE = -I/usr/local/include
+INCLUDE = -I$(PREFIX)/include
 CFLAGS = -shared -DDEBUG -Og -ggdb -Wall -fPIC
-LDFLAGS = -L/usr/local/lib -llua -llsuprdf_dbg
+LDFLAGS = -L$(PREFIX)/lib -llua -lvolksdata_dbg
 
 LUAC_SRC = $(wildcard src/*.c)
 #OBJ = $(patsubst src/%.c, lib/%.so, $(LUAC_SRC))
-OBJ = lsup.so
+OBJ = volksdata.so
 OBJPATH = lib/$(OBJ)
 
 LUA_VER=5.4
@@ -14,7 +14,7 @@ INSTALL_SUFFIX=lib/lua/$(LUA_VER)
 INSTALL_DIR=$(PREFIX)/$(INSTALL_SUFFIX)
 LOCAL_INSTALL_DIR=$(shell luarocks config home_tree)/$(INSTALL_SUFFIX)
 
-VALGRIND_LOG=/tmp/lua_lsup_valgrind.log
+VALGRIND_LOG=/tmp/lua_volksdata_valgrind.log
 
 .DEFAULT_GOAL := lib
 
@@ -23,7 +23,7 @@ VALGRIND_LOG=/tmp/lua_lsup_valgrind.log
 lib: $(OBJPATH)
 
 
-$(OBJPATH): src/*.c src/lua_lsup.h
+$(OBJPATH): src/*.c src/lua_volksdata.h
 	$(CC) $(INCLUDE) $(CFLAGS) $(LDFLAGS) -o $@ src/*.c
 
 

+ 2 - 2
README.md

@@ -1,6 +1,6 @@
-# `lsup_lua`
+# `volksdata-lua`
 
-Lua bindings for [`lsup_rdf`](https://git.knowledgetx.com/scossu/lsup_rdf).
+Lua bindings for [Volksdata](https://git.knowledgetx.com/scossu/volksdata).
 
 ## Status
 

+ 182 - 154
src/lua_graph.c

@@ -1,51 +1,47 @@
-#include "lua_lsup.h"
+#include "lua_volksdata.h"
 
 
-LSUP_rc
-term_set_to_table (lua_State *L, LSUP_TermSet *ts)
+static VOLK_Graph **allocate_graph (lua_State *L)
 {
-    size_t i = 0;
-    LSUP_Term *tmp = NULL;
-    LSUP_rc rc;
-    lua_newtable (L);
-    while ((rc = LSUP_term_set_next (ts, &i, &tmp)) == LSUP_OK) {
-        LSUP_Term **t2_p = (LSUP_Term **)lua_newuserdata (L, sizeof *t2_p);
-        luaL_getmetatable (L, "LSUP.Term");
-        lua_setmetatable (L, -2);
-        *t2_p = LSUP_term_copy (tmp);
-
-        lua_pushboolean (L, true);
-        lua_rawset (L, -3);
-    }
-
-    if (rc < LSUP_OK) return rc;
-    return LSUP_OK;
-}
-
-
-static LSUP_Graph **allocate_graph (lua_State *L)
-{
-    LSUP_Graph **gp = lua_newuserdatauv (L, sizeof (*gp), 1);
-    luaL_getmetatable (L, "LSUP.Graph");
+    VOLK_Graph **gp = lua_newuserdatauv (L, sizeof (*gp), 1);
+    luaL_getmetatable (L, "VOLK.Graph");
     lua_setmetatable (L, -2);
 
     return gp;
 }
 
 
+/** @brief Create a new graph.
+ *
+ * @param[in] store The store to use as a back end. if unspecified, an
+ * in-memory hashmap is used.
+ *
+ * @param[in] uri_str String to use as the graph URI. It may be namespace-
+ * prefixed, or fully qualified. If not specified, Volksdata generates a
+ * UUID4 URN.
+ *
+ * @param[in[ is_ns Whether the passed string is a namespace-prefixed URI.
+ *  Default is false. If this is true, the `uri_str` parameter MUST be passed.
+ */
 static int l_graph_new (lua_State *L)
 {
-    LSUP_Store *store;
+    VOLK_Store *store;
     if (lua_isnoneornil (L, 1)) store = NULL;
-    else store = *(LSUP_Store **)luaL_checkudata (L, 1, "LSUP.Store");
+    else store = *(VOLK_Store **)luaL_checkudata (L, 1, "VOLK.Store");
 
     const char *uri_str = lua_tostring (L, 2);
+    bool is_ns = lua_toboolean (L, 3);
 
-    LSUP_Graph **gp = allocate_graph (L);
+    if (is_ns && !uri_str)
+        luaL_error (L, "URI must be passed if is_ns is true.", 2);
 
-    *gp = LSUP_graph_new (store, uri_str);
-    LOG_DEBUG ("New graph URI @%p: %s", *gp, LSUP_graph_uri (*gp)->data);
+    VOLK_Graph **gp = allocate_graph (L);
+
+    *gp = is_ns ?
+        VOLK_graph_new_ns (store, uri_str) :
+        VOLK_graph_new (store, uri_str);
     LUA_NLCHECK (*gp, "Error creating graph.");
+    LOG_DEBUG ("New graph URI @%p: %s", *gp, VOLK_graph_uri (*gp)->data);
 
     return 1;
 }
@@ -53,10 +49,10 @@ static int l_graph_new (lua_State *L)
 
 static int l_graph_list (lua_State *L)
 {
-    const LSUP_Store *store = *(LSUP_Store **)luaL_checkudata (
-            L, 1, "LSUP.Store");
+    const VOLK_Store *store = *(VOLK_Store **)luaL_checkudata (
+            L, 1, "VOLK.Store");
 
-    LSUP_TermSet *ts = LSUP_graph_list (store);
+    VOLK_TermSet *ts = VOLK_graph_list (store);
     LUA_NLCHECK (ts, "Error retrieving context list.");
     LUA_PCHECK (term_set_to_table (L, ts), "Error generating term set table");
 
@@ -70,10 +66,10 @@ static int l_graph_list (lua_State *L)
 
 static int l_graph_gc (lua_State *L)
 {
-    LSUP_Graph **gp = luaL_checkudata(L, 1, "LSUP.Graph");
+    VOLK_Graph **gp = luaL_checkudata(L, 1, "VOLK.Graph");
     LOG_DEBUG ("Garbage collecting graph @%p", *gp);
 
-    LSUP_graph_free (*gp);
+    VOLK_graph_free (*gp);
     *gp = NULL;
 
     return 0;
@@ -82,13 +78,13 @@ static int l_graph_gc (lua_State *L)
 
 static int l_graph_get_uri (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
+    const VOLK_Graph *gr = check_graph (L);
 
-    LSUP_Term **tp = lua_newuserdata (L, sizeof *tp);
-    luaL_getmetatable (L, "LSUP.Term");
+    VOLK_Term **tp = lua_newuserdata (L, sizeof *tp);
+    luaL_getmetatable (L, "VOLK.Term");
     lua_setmetatable (L, -2);
 
-    *tp = LSUP_term_copy (LSUP_graph_uri (gr));
+    *tp = VOLK_term_copy (VOLK_graph_uri (gr));
     LUA_NLCHECK (*tp, "Error getting graph URI.");
 
     return 1;
@@ -97,10 +93,10 @@ static int l_graph_get_uri (lua_State *L)
 
 static int l_graph_to_string (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
+    const VOLK_Graph *gr = check_graph (L);
     lua_pushfstring (
-            L, "LSUP.Graph @%p <%s>: %d triples",
-            gr, LSUP_graph_uri (gr)->data, LSUP_graph_size (gr));
+            L, "VOLK.Graph @%p <%s>: %d triples",
+            gr, VOLK_graph_uri (gr)->data, VOLK_graph_size (gr));
 
     return 1;
 }
@@ -108,8 +104,8 @@ static int l_graph_to_string (lua_State *L)
 
 static int l_graph_len (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
-    lua_pushinteger (L, LSUP_graph_size (gr));
+    const VOLK_Graph *gr = check_graph (L);
+    lua_pushinteger (L, VOLK_graph_size (gr));
 
     return 1;
 }
@@ -117,29 +113,18 @@ static int l_graph_len (lua_State *L)
 
 static int l_graph_copy (lua_State *L)
 {
-    const LSUP_Graph *src = check_graph (L);
-    LSUP_Graph *dest = *(LSUP_Graph **)luaL_checkudata(L, 2, "LSUP.Graph");
-
-    LUA_PCHECK (LSUP_graph_copy (src, dest), "Error copying graph");
-
-    return 1;
-}
-
-
-static int l_graph_copy_contents (lua_State *L)
-{
-    const LSUP_Graph *src = check_graph (L);
-    LSUP_Graph *dest = *(LSUP_Graph **)luaL_checkudata (L, 2, "LSUP.Graph");
-    const LSUP_Term *s, *p, *o;
+    const VOLK_Graph *src = check_graph (L);
+    VOLK_Graph *dest = *(VOLK_Graph **)luaL_checkudata (L, 2, "VOLK.Graph");
+    const VOLK_Term *s, *p, *o;
 
     if lua_isnoneornil (L, 3) s = NULL;
-    else s = *(LSUP_Term **)luaL_checkudata (L, 3, "LSUP.Term");
+    else s = *(VOLK_Term **)luaL_checkudata (L, 3, "VOLK.Term");
     if lua_isnoneornil (L, 4) p = NULL;
-    else p = *(LSUP_Term **)luaL_checkudata (L, 4, "LSUP.Term");
+    else p = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
     if lua_isnoneornil (L, 5) o = NULL;
-    else o = *(LSUP_Term **)luaL_checkudata (L, 5, "LSUP.Term");
+    else o = *(VOLK_Term **)luaL_checkudata (L, 5, "VOLK.Term");
 
-    LUA_PCHECK (LSUP_graph_copy_contents (
+    LUA_PCHECK (VOLK_graph_copy_contents (
                 src, dest, s, p, o), "Error copying graph.");
 
     return 1;
@@ -148,12 +133,12 @@ static int l_graph_copy_contents (lua_State *L)
 
 static int l_graph_equals (lua_State *L)
 {
-    const LSUP_Graph *gr1 = check_graph (L);
-    const LSUP_Graph *gr2 =
-        *(LSUP_Graph **)luaL_checkudata (L, 2, "LSUP.Graph");
+    const VOLK_Graph *gr1 = check_graph (L);
+    const VOLK_Graph *gr2 =
+        *(VOLK_Graph **)luaL_checkudata (L, 2, "VOLK.Graph");
 
     LOG_DEBUG ("Comparing graphs %p %p", gr1, gr2);
-    int eq_rc = LSUP_graph_equals (gr1, gr2);
+    int eq_rc = VOLK_graph_equals (gr1, gr2);
     lua_pushboolean (L, eq_rc);
 
     return 1;
@@ -162,11 +147,11 @@ static int l_graph_equals (lua_State *L)
 
 static int l_graph_contains (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
-    const LSUP_Triple *spo =
-        *(LSUP_Triple **)luaL_checkudata (L, 2, "LSUP.Triple");
+    const VOLK_Graph *gr = check_graph (L);
+    const VOLK_Triple *spo =
+        *(VOLK_Triple **)luaL_checkudata (L, 2, "VOLK.Triple");
 
-    lua_pushboolean (L, LSUP_graph_contains (gr, spo));
+    lua_pushboolean (L, VOLK_graph_contains (gr, spo));
 
     return 1;
 }
@@ -175,13 +160,13 @@ static int l_graph_contains (lua_State *L)
 /// Initialize iterative addition.
 static int l_graph_add_init (lua_State *L)
 {
-    LSUP_Graph *gr = check_graph (L);
+    VOLK_Graph *gr = check_graph (L);
 
-    LSUP_GraphIterator **it_p = lua_newuserdata (L, sizeof *it_p);
-    luaL_getmetatable (L, "LSUP.GraphIterator");
+    VOLK_GraphIterator **it_p = lua_newuserdata (L, sizeof *it_p);
+    luaL_getmetatable (L, "VOLK.GraphIterator");
     lua_setmetatable (L, -2);
 
-    *it_p = LSUP_graph_add_init (gr);
+    *it_p = VOLK_graph_add_init (gr);
     LUA_NLCHECK (*it_p, "Error creating graph iterator.");
 
     return 1;
@@ -191,10 +176,10 @@ static int l_graph_add_init (lua_State *L)
 /// Add one triple.
 static int l_graph_add_iter (lua_State *L)
 {
-    LSUP_GraphIterator **it_p = luaL_checkudata (L, 1, "LSUP.GraphIterator");
-    const LSUP_Triple **spo = luaL_checkudata (L, 2, "LSUP.Triple");
+    VOLK_GraphIterator **it_p = luaL_checkudata (L, 1, "VOLK.GraphIterator");
+    const VOLK_Triple **spo = luaL_checkudata (L, 2, "VOLK.Triple");
 
-    LUA_PCHECK (LSUP_graph_add_iter (*it_p, *spo), "Error adding triple");
+    LUA_PCHECK (VOLK_graph_add_iter (*it_p, *spo), "Error adding triple");
 
     return 0;
 }
@@ -203,8 +188,8 @@ static int l_graph_add_iter (lua_State *L)
 /// Finalize iterative addition.
 static int l_graph_add_done (lua_State *L)
 {
-    LSUP_GraphIterator **it_p = lua_touserdata (L, 1);
-    LSUP_graph_add_done (*it_p);
+    VOLK_GraphIterator **it_p = lua_touserdata (L, 1);
+    VOLK_graph_add_done (*it_p);
 
     return 0;
 }
@@ -214,47 +199,47 @@ static int l_graph_add_done (lua_State *L)
  */
 static int l_graph_add (lua_State *L)
 {
-    LSUP_Graph *gr = check_graph (L);
+    VOLK_Graph *gr = check_graph (L);
     int rc;
-    LSUP_rc lsup_rc= LSUP_NOACTION;
+    VOLK_rc volk_rc= VOLK_NOACTION;
     size_t i = 0, ct = 0;
-    LSUP_GraphIterator *it = LSUP_graph_add_init (gr);
+    VOLK_GraphIterator *it = VOLK_graph_add_init (gr);
 
     while ((rc = lua_rawgeti (L, 2, ++i)) != LUA_TNIL) {
         //LOG_DEBUG ("Triple type: %s", lua_typename (L, rc));
-        const LSUP_Triple *spo =
-            *(LSUP_Triple **)luaL_checkudata (L, -1, "LSUP.Triple");
+        const VOLK_Triple *spo =
+            *(VOLK_Triple **)luaL_checkudata (L, -1, "VOLK.Triple");
         LOG_DEBUG (
                 "Got triple %d: {%s %s %s}\n",
                 i, spo->s->data, spo->p->data, spo->o->data);
-        lsup_rc = LSUP_graph_add_iter (it, spo);
+        volk_rc = VOLK_graph_add_iter (it, spo);
 
-        if (lsup_rc < LSUP_OK) break;
-        if (lsup_rc == LSUP_OK) ct++;
+        if (volk_rc < VOLK_OK) break;
+        if (volk_rc == VOLK_OK) ct++;
     };
-    LSUP_graph_add_done (it);
+    VOLK_graph_add_done (it);
     lua_pushinteger (L, ct);
 
-    if (UNLIKELY (lsup_rc < LSUP_OK)) return luaL_error (
+    if (UNLIKELY (volk_rc < VOLK_OK)) return luaL_error (
             L, "Error adding triple at position %d: %s",
-            i, LSUP_strerror (lsup_rc));
+            i, VOLK_strerror (volk_rc));
     else return 1;
 }
 
 
 static int l_graph_remove (lua_State *L)
 {
-    LSUP_Graph *gr = check_graph (L);
-    const LSUP_Term *s, *p, *o;
+    VOLK_Graph *gr = check_graph (L);
+    const VOLK_Term *s, *p, *o;
     if lua_isnoneornil (L, 2) s = NULL;
-    else s = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
+    else s = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
     if lua_isnoneornil (L, 3) p = NULL;
-    else p = *(LSUP_Term **)luaL_checkudata (L, 3, "LSUP.Term");
+    else p = *(VOLK_Term **)luaL_checkudata (L, 3, "VOLK.Term");
     if lua_isnoneornil (L, 4) o = NULL;
-    else o = *(LSUP_Term **)luaL_checkudata (L, 4, "LSUP.Term");
+    else o = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
 
     size_t ct;
-    LSUP_rc rc = LSUP_graph_remove (gr, s, p, o, &ct);
+    VOLK_rc rc = VOLK_graph_remove (gr, s, p, o, &ct);
 
     LUA_PCHECK (rc, "Error removing triples from graph.");
     lua_pushinteger (L, ct);
@@ -265,20 +250,20 @@ static int l_graph_remove (lua_State *L)
 
 static int graph_iter_next (lua_State *L)
 {
-    LSUP_GraphIterator **it_p = lua_touserdata (L, lua_upvalueindex (1));
+    VOLK_GraphIterator **it_p = lua_touserdata (L, lua_upvalueindex (1));
 
-    LSUP_Triple **spo_p = lua_newuserdatauv (L, sizeof (*spo_p), 1);
-    luaL_getmetatable (L, "LSUP.Triple");
+    VOLK_Triple **spo_p = lua_newuserdatauv (L, sizeof (*spo_p), 1);
+    luaL_getmetatable (L, "VOLK.Triple");
     lua_setmetatable (L, -2);
     *spo_p = NULL;
 
-    LSUP_rc rc = LSUP_graph_iter_next (*it_p, spo_p);
+    VOLK_rc rc = VOLK_graph_iter_next (*it_p, spo_p);
 
-    if (rc != LSUP_OK) {
-        LSUP_graph_iter_free (*it_p);
+    if (rc != VOLK_OK) {
+        VOLK_graph_iter_free (*it_p);
         *it_p = NULL;
 
-        if (rc == LSUP_END) {
+        if (rc == VOLK_END) {
             lua_pushnil (L);
             lua_pushstring (L, "End of lookup results.");
             return 2;
@@ -293,22 +278,22 @@ static int graph_iter_next (lua_State *L)
 
 static int l_graph_lookup (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
-    const LSUP_Term *s, *p, *o;
+    const VOLK_Graph *gr = check_graph (L);
+    const VOLK_Term *s, *p, *o;
     if lua_isnoneornil (L, 2) s = NULL;
-    else s = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
+    else s = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
     if lua_isnoneornil (L, 3) p = NULL;
-    else p = *(LSUP_Term **)luaL_checkudata (L, 3, "LSUP.Term");
+    else p = *(VOLK_Term **)luaL_checkudata (L, 3, "VOLK.Term");
     if lua_isnoneornil (L, 4) o = NULL;
-    else o = *(LSUP_Term **)luaL_checkudata (L, 4, "LSUP.Term");
+    else o = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
 
-    LSUP_GraphIterator **it_p = lua_newuserdata (L, sizeof *it_p);
+    VOLK_GraphIterator **it_p = lua_newuserdata (L, sizeof *it_p);
     *it_p = NULL;
-    luaL_getmetatable (L, "LSUP.GraphIterator");
+    luaL_getmetatable (L, "VOLK.GraphIterator");
     lua_setmetatable (L, -2);
 
     size_t ct;
-    *it_p = LSUP_graph_lookup (gr, s, p, o, &ct);
+    *it_p = VOLK_graph_lookup (gr, s, p, o, &ct);
     LUA_NLCHECK (*it_p, "Error creating graph iterator.");
     LOG_DEBUG ("Found triples: %d", ct);
 
@@ -318,14 +303,52 @@ static int l_graph_lookup (lua_State *L)
 }
 
 
+static int l_graph_encode (lua_State *L)
+{
+    const VOLK_Graph *gr = check_graph (L);
+    const char *codec_str = lua_tostring (L, 2);
+
+    VOLK_Codec codec;
+    if (strcmp(codec_str, "nt") == 0)
+        codec = nt_codec;
+    else if (strcmp(codec_str, "ttl") == 0)
+        codec = ttl_codec;
+    else
+        return luaL_error(L, "Invalid encoding format: %s", codec_str);
+
+    char *out = calloc (1, 1);
+    LUA_NLCHECK (out, "Error allocating codec iterator.");
+    void *it = codec.encode_graph_init (gr);
+    LUA_NLCHECK (it, "Error creating codec iterator.");
+
+    char *tmp = NULL;
+    VOLK_rc rc;
+    while ((rc = codec.encode_graph_iter (it, &tmp)) != VOLK_END) {
+        log_debug ("Serialized fragment: %s\n", tmp);
+        LUA_PCHECK (rc, "Encoding failed");
+        out = realloc (out, strlen(out) + strlen (tmp) + 1);
+        LUA_NLCHECK (out, "Error reallocating serialization buffer.");
+        out = strcat (out, tmp);
+        LUA_NLCHECK (out, "Error filling serialization buffer.");
+    }
+    codec.encode_graph_done (it);
+
+    lua_pushstring (L, out);
+    free (tmp);
+    free (out);
+
+    return 1;
+}
+
+
 static int l_graph_get (lua_State *L)
 {
-    LSUP_Term *gr_uri = check_term (L);
-    LSUP_Store *store = *(LSUP_Store **)luaL_checkudata (L, 2, "LSUP.Store");
+    VOLK_Term *gr_uri = check_term (L);
+    VOLK_Store *store = *(VOLK_Store **)luaL_checkudata (L, 2, "VOLK.Store");
 
-    LSUP_Graph **gp = allocate_graph (L);
+    VOLK_Graph **gp = allocate_graph (L);
     size_t ct;
-    *gp = LSUP_graph_get (store, gr_uri, &ct);
+    *gp = VOLK_graph_get (store, gr_uri, &ct);
     lua_pushinteger (L, ct);
 
     return 2;
@@ -344,12 +367,12 @@ static int l_graph_get (lua_State *L)
  */
 static int graph_iter_gc (lua_State *L)
 {
-    LSUP_GraphIterator **it_p = lua_touserdata (L, 1);
+    VOLK_GraphIterator **it_p = lua_touserdata (L, 1);
 
     if (UNLIKELY (!it_p || !*it_p)) return 0;
     LOG_DEBUG ("Garbage collecting iterator @%p", it_p);
 
-    LSUP_graph_iter_free (*it_p);
+    VOLK_graph_iter_free (*it_p);
     *it_p = NULL;
 
     return 0;
@@ -360,15 +383,15 @@ static int graph_iter_gc (lua_State *L)
  */
 static int l_graph_connections (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
-    LSUP_Term *t = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
-    const LSUP_LinkType type = luaL_checkinteger (L, 3);
+    const VOLK_Graph *gr = check_graph (L);
+    VOLK_Term *t = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
+    const VOLK_LinkType type = luaL_checkinteger (L, 3);
     LOG_DEBUG ("Adding term for connections: @%p", *t);
 
-    LSUP_LinkMap **lm_p = lua_newuserdata (L, sizeof *lm_p);
-    *lm_p = LSUP_graph_connections (gr, t, type);
+    VOLK_LinkMap **lm_p = lua_newuserdata (L, sizeof *lm_p);
+    *lm_p = VOLK_graph_connections (gr, t, type);
     LUA_NLCHECK (*lm_p, "Error creating Link map.");
-    luaL_getmetatable (L, "LSUP.LinkMap");
+    luaL_getmetatable (L, "VOLK.LinkMap");
     lua_setmetatable (L, -2);
 
     return 1;
@@ -377,13 +400,13 @@ static int l_graph_connections (lua_State *L)
 
 static int l_graph_term_set (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
-    const LSUP_Term *t1 = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
-    const LSUP_TriplePos t1_pos = luaL_checkinteger (L, 3);
-    const LSUP_Term *t2 = *(LSUP_Term **)luaL_checkudata (L, 4, "LSUP.Term");
-    const LSUP_TriplePos t2_pos = luaL_checkinteger (L, 5);
+    const VOLK_Graph *gr = check_graph (L);
+    const VOLK_Term *t1 = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
+    const VOLK_TriplePos t1_pos = luaL_checkinteger (L, 3);
+    const VOLK_Term *t2 = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
+    const VOLK_TriplePos t2_pos = luaL_checkinteger (L, 5);
 
-    LSUP_TermSet *ts = LSUP_graph_term_set (gr, t1, t1_pos, t2, t2_pos);
+    VOLK_TermSet *ts = VOLK_graph_term_set (gr, t1, t1_pos, t2, t2_pos);
     LUA_NLCHECK (ts, "Error creating term set from graph.");
     LUA_PCHECK (term_set_to_table (L, ts), "Error generating term set table");
 
@@ -393,10 +416,10 @@ static int l_graph_term_set (lua_State *L)
 
 static int l_graph_unique_terms (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
-    const LSUP_TriplePos pos = luaL_checkinteger (L, 2);
+    const VOLK_Graph *gr = check_graph (L);
+    const VOLK_TriplePos pos = luaL_checkinteger (L, 2);
 
-    LSUP_TermSet *ts = LSUP_graph_unique_terms (gr, pos);
+    VOLK_TermSet *ts = VOLK_graph_unique_terms (gr, pos);
     LUA_NLCHECK (ts, "Error creating term set from unique terms.");
     LUA_PCHECK (term_set_to_table (L, ts), "Error generating term set table");
 
@@ -404,7 +427,7 @@ static int l_graph_unique_terms (lua_State *L)
 }
 
 
-/** @brief Get all o's for given s and p as a set (Lua table) of values.
+/** @brief Get all o's for given s and p as a table of values.
  *
  * @param[in] gr Graph to query from.
  *
@@ -412,32 +435,38 @@ static int l_graph_unique_terms (lua_State *L)
  *
  * @param[in] p Predicate to query.
  *
- * @return Table (set) of objects found per sp combination.
+ * @return Table of objects found per sp combination.
+ *
+ * @todo This could be reformatted as a term set generator, but it seems more
+ *  efficient this way because it iterates over the results only once.
  */
 static int l_graph_attr (lua_State *L)
 {
-    const LSUP_Graph *gr = check_graph (L);
-    const LSUP_Term *s = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
-    const LSUP_Term *p = *(LSUP_Term **)luaL_checkudata (L, 3, "LSUP.Term");
+    const VOLK_Graph *gr = check_graph (L);
+    const VOLK_Term *s = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
+    const VOLK_Term *p = *(VOLK_Term **)luaL_checkudata (L, 3, "VOLK.Term");
 
     size_t ct;
-    LSUP_GraphIterator *it = LSUP_graph_lookup (gr, s, p, NULL, &ct);
+    VOLK_GraphIterator *it = VOLK_graph_lookup (gr, s, p, NULL, &ct);
 
     lua_createtable (L, ct, 0);
-    LSUP_Triple *spo;
-    LSUP_rc rc;
-    while ((rc = LSUP_graph_iter_next (it, &spo)) == LSUP_OK) {
-        LSUP_Term **op = lua_newuserdata (L, sizeof *op);
-        luaL_getmetatable (L, "LSUP.Term");
+    VOLK_Triple *spo;
+    VOLK_rc rc;
+    while ((rc = VOLK_graph_iter_next (it, &spo)) == VOLK_OK) {
+        // Table keys are term hashes.
+        lua_pushinteger (L, VOLK_term_hash (spo->o));
+
+        // Table values are the term sets proper.
+        VOLK_Term **op = lua_newuserdata (L, sizeof *op);
+        luaL_getmetatable (L, "VOLK.Term");
         lua_setmetatable (L, -2);
-        *op = LSUP_term_copy (spo->o);
-        lua_pushboolean (L, true);
+        *op = VOLK_term_copy (spo->o);
 
         lua_rawset (L, -3);
     }
-    LSUP_graph_iter_free (it);
+    VOLK_graph_iter_free (it);
 
-    if (rc != LSUP_END) LUA_PCHECK (rc, "Error iterating attr values");
+    if (rc != VOLK_END) LUA_PCHECK (rc, "Error iterating attr values");
 
     return 1;
 }
@@ -482,7 +511,6 @@ static const luaL_Reg graph_lib_meth [] = {
     {"__len", l_graph_len},
 
     {"copy", l_graph_copy},
-    {"copy_contents", l_graph_copy_contents},
 
     {"add", l_graph_add},
     {"remove", l_graph_remove},
@@ -494,8 +522,8 @@ static const luaL_Reg graph_lib_meth [] = {
     {"term_set", l_graph_term_set},
     {"unique_terms", l_graph_unique_terms},
     {"attr", l_graph_attr},
+    {"encode", l_graph_encode},
 
-    //{"to_n3", l_graph_to_n3},
     {NULL}
 };
 
@@ -505,16 +533,16 @@ static const LEnumConst graph_enums[] = {
 };
 
 
-int luaopen_lsup_graph (lua_State *L)
+int luaopen_volksdata_graph (lua_State *L)
 {
-    LSUP_init();  // This is idempotent: no problem calling it multiple times.
-    luaL_newmetatable (L, "LSUP.Graph");
+    VOLK_init();  // This is idempotent: no problem calling it multiple times.
+    luaL_newmetatable (L, "VOLK.Graph");
     lua_pushvalue (L, -1);
     lua_setfield (L, -2, "__index");
     luaL_setfuncs (L, graph_lib_meth, 0);
 
     // Metatables for ancillary types.
-    luaL_newmetatable (L, "LSUP.GraphIterator");
+    luaL_newmetatable (L, "VOLK.GraphIterator");
     lua_pushcfunction (L, graph_iter_gc);
     lua_setfield (L, -2, "__gc");
 

+ 12 - 12
src/lua_namespace.c

@@ -1,4 +1,4 @@
-#include "lua_lsup.h"
+#include "lua_volksdata.h"
 
 
 /*
@@ -12,7 +12,7 @@ static int l_nsmap_add (lua_State *L)
         *nsstr = luaL_checkstring (L, 2);
 
     LUA_PCHECK (
-            LSUP_nsmap_add (pfx, nsstr),
+            VOLK_nsmap_add (pfx, nsstr),
             "Error adding member to NS map");
 
     return 0;
@@ -24,7 +24,7 @@ static int l_nsmap_remove (lua_State *L)
     const char *pfx = luaL_checkstring (L, 1);
 
     LUA_PCHECK (
-            LSUP_nsmap_remove (pfx),
+            VOLK_nsmap_remove (pfx),
             "Error removing member to NS map");
 
     return 0;
@@ -35,7 +35,7 @@ static int l_nsmap_get_ns (lua_State *L)
 {
     const char *pfx = luaL_checkstring (L, 1);
 
-    const char *ns = LSUP_nsmap_get_ns (pfx);
+    const char *ns = VOLK_nsmap_get_ns (pfx);
 
     if (ns) lua_pushstring (L, ns);
     else return 0;
@@ -48,7 +48,7 @@ static int l_nsmap_get_pfx (lua_State *L)
 {
     const char *ns = luaL_checkstring (L, 1);
 
-    const char *pfx = LSUP_nsmap_get_pfx (ns);
+    const char *pfx = VOLK_nsmap_get_pfx (ns);
 
     if (pfx) lua_pushstring (L, pfx);
     else lua_pushnil (L);
@@ -63,7 +63,7 @@ static int l_nsmap_normalize_uri (lua_State *L)
 
     char *fq_uri;
     LUA_PCHECK (
-            LSUP_nsmap_normalize_uri (pfx_uri, &fq_uri),
+            VOLK_nsmap_normalize_uri (pfx_uri, &fq_uri),
             "Error normalizing URI");
 
     if (fq_uri) lua_pushstring (L, fq_uri);
@@ -80,7 +80,7 @@ static int l_nsmap_denormalize_uri (lua_State *L)
 
     char *pfx_uri;
     LUA_PCHECK (
-            LSUP_nsmap_denormalize_uri (fq_uri, &pfx_uri),
+            VOLK_nsmap_denormalize_uri (fq_uri, &pfx_uri),
             "Error denormalizing URI");
 
     if (pfx_uri) lua_pushstring (L, pfx_uri);
@@ -116,9 +116,9 @@ static int nsmap_iter_next (lua_State *L)
 static int l_nsmap_iter (lua_State *L)
 {
     const char ****data_p = lua_newuserdata (L, sizeof (*data_p));
-    //luaL_getmetatable (L, "LSUP.String2DIterator");
+    //luaL_getmetatable (L, "VOLK.String2DIterator");
     //lua_setmetatable (L, -2);
-    *data_p = LSUP_nsmap_dump ();
+    *data_p = VOLK_nsmap_dump ();
     LUA_NLCHECK (*data_p, "Error creating NS map iterator.");
 
     size_t *i = malloc (sizeof (*i));
@@ -156,15 +156,15 @@ static const luaL_Reg nsmap_lib_meth [] = {
 */
 
 
-int luaopen_lsup_namespace (lua_State *L)
+int luaopen_volksdata_namespace (lua_State *L)
 {
-    luaL_newmetatable (L, "LSUP.NSMap");
+    luaL_newmetatable (L, "VOLK.NSMap");
     lua_pushvalue (L, -1);
     //lua_setfield (L, -2, "__index");
     //luaL_setfuncs (L, nsmap_lib_meth, 0);
     luaL_newlib (L, nsmap_lib_fn);
 
-    //luaL_newmetatable (L, "LSUP.String2DIterator");
+    //luaL_newmetatable (L, "VOLK.String2DIterator");
 
     return 1;
 }

+ 16 - 16
src/lua_store.c

@@ -1,19 +1,19 @@
-#include "lua_lsup.h"
+#include "lua_volksdata.h"
 
 
 static int l_store_new (lua_State *L)
 {
-    const LSUP_StoreType store_type = luaL_checkinteger (L, 1);
+    const VOLK_StoreType store_type = luaL_checkinteger (L, 1);
     const char *id = luaL_optstring (L, 2, NULL);
     const bool clear = lua_toboolean (L, 3);
 
-    LSUP_Store **store_p = lua_newuserdatauv (L, sizeof (*store_p), 1);
-    luaL_getmetatable (L, "LSUP.Store");
+    VOLK_Store **store_p = lua_newuserdatauv (L, sizeof (*store_p), 1);
+    luaL_getmetatable (L, "VOLK.Store");
     lua_setmetatable (L, -2);
 
     // Set up the store if a function for that is defined.
     if (clear) log_info ("Clearing old store.");
-    *store_p = LSUP_store_new (store_type, id, 0, clear);
+    *store_p = VOLK_store_new (store_type, id, 0, clear);
     LUA_NLCHECK (*store_p, "Error creating back end store.");
 
     return 1;
@@ -22,10 +22,10 @@ static int l_store_new (lua_State *L)
 
 static int store_gc (lua_State *L)
 {
-    LSUP_Store **sp = luaL_checkudata(L, 1, "LSUP.Store");
+    VOLK_Store **sp = luaL_checkudata(L, 1, "VOLK.Store");
     LOG_DEBUG ("Garbage collecting store @%p.", *sp);
 
-    LSUP_store_free (*sp);
+    VOLK_store_free (*sp);
     *sp = NULL;
 
     return 0;
@@ -34,12 +34,12 @@ static int store_gc (lua_State *L)
 
 static int l_store_tostring (lua_State *L)
 {
-    const LSUP_Store *store = *(LSUP_Store **) luaL_checkudata (
-            L, 1, "LSUP.Store");
+    const VOLK_Store *store = *(VOLK_Store **) luaL_checkudata (
+            L, 1, "VOLK.Store");
     lua_pushfstring (
-            L, "LSUP.Store @%p <%s>: %s",
+            L, "VOLK.Store @%p <%s>: %s",
             store,
-            LSUP_store_type_label (store->type),
+            VOLK_store_type_label (store->type),
             store->id);
 
     return 1;
@@ -65,17 +65,17 @@ static const luaL_Reg store_lib_meth [] = {
 
 
 static const LEnumConst store_enums[] = {
-    {"HTABLE", LSUP_STORE_HTABLE},
-    {"MDB", LSUP_STORE_MDB},
+    {"HTABLE", VOLK_STORE_HTABLE},
+    {"MDB", VOLK_STORE_MDB},
 
     {NULL, 0}
 };
 
 
-int luaopen_lsup_store (lua_State *L)
+int luaopen_volksdata_store (lua_State *L)
 {
-    LSUP_init();  // This is idempotent: no problem calling it multiple times.
-    luaL_newmetatable (L, "LSUP.Store");
+    VOLK_init();  // This is idempotent: no problem calling it multiple times.
+    luaL_newmetatable (L, "VOLK.Store");
     lua_pushvalue (L, -1);
     lua_setfield (L, -2, "__index");
     luaL_setfuncs (L, store_lib_meth, 0);

+ 111 - 86
src/lua_term.c

@@ -1,27 +1,52 @@
-#include "lua_lsup.h"
+#include "lua_volksdata.h"
 #include "stackdump.h"
 
 
-LSUP_Term **allocate_term (lua_State *L)
+VOLK_Term **allocate_term (lua_State *L)
 {
-    LSUP_Term **tp = lua_newuserdatauv (L, sizeof (*tp), 1);
-    luaL_getmetatable (L, "LSUP.Term");
+    VOLK_Term **tp = lua_newuserdatauv (L, sizeof (*tp), 1);
+    luaL_getmetatable (L, "VOLK.Term");
     lua_setmetatable (L, -2);
 
     return tp;
 }
 
 
-LSUP_TermSet **allocate_tset (lua_State *L)
+VOLK_TermSet **allocate_tset (lua_State *L)
 {
-    LSUP_TermSet **ts_p = lua_newuserdatauv (L, sizeof (*ts_p), 1);
-    luaL_getmetatable (L, "LSUP.TermSet");
+    VOLK_TermSet **ts_p = lua_newuserdatauv (L, sizeof (*ts_p), 1);
+    luaL_getmetatable (L, "VOLK.TermSet");
     lua_setmetatable (L, -2);
 
     return ts_p;
 }
 
 
+VOLK_rc
+term_set_to_table (lua_State *L, VOLK_TermSet *ts)
+{
+    size_t i = 0;
+    VOLK_Term *tmp = NULL;
+    VOLK_rc rc;
+    lua_newtable (L);
+    while ((rc = VOLK_term_set_next (ts, &i, &tmp)) == VOLK_OK) {
+        // Table keys are term hashes.
+        lua_pushinteger (L, VOLK_term_hash (tmp));
+
+        // Table values are the term sets proper.
+        VOLK_Term **tp = (VOLK_Term **)lua_newuserdata (L, sizeof *tp);
+        luaL_getmetatable (L, "VOLK.Term");
+        lua_setmetatable (L, -2);
+        *tp = VOLK_term_copy (tmp);
+
+        lua_rawset (L, -3);
+    }
+
+    if (rc < VOLK_OK) return rc;
+    return VOLK_OK;
+}
+
+
 /*
  * Factory methods.
  */
@@ -30,9 +55,9 @@ static int l_new_iriref (lua_State *L)
 {
     const char *data = luaL_checkstring (L, 1);
 
-    LSUP_Term **tp = allocate_term (L);
+    VOLK_Term **tp = allocate_term (L);
 
-    *tp = LSUP_iriref_new (data);
+    *tp = VOLK_iriref_new (data);
     LUA_NLCHECK (*tp, "Error creating term.");
 
     return 1;
@@ -43,9 +68,9 @@ static int l_new_iriref_ns (lua_State *L)
 {
     const char *data = luaL_checkstring (L, 1);
 
-    LSUP_Term **tp = allocate_term (L);
+    VOLK_Term **tp = allocate_term (L);
 
-    *tp = LSUP_iriref_new_ns (data);
+    *tp = VOLK_iriref_new_ns (data);
     LUA_NLCHECK (*tp, "Error creating term.");
 
     return 1;
@@ -54,13 +79,13 @@ static int l_new_iriref_ns (lua_State *L)
 
 static int l_new_iriref_abs (lua_State *L)
 {
-    LSUP_Term
+    VOLK_Term
         *root = check_term (L),
-        *iri = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
+        *iri = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
 
-    LSUP_Term **tp = allocate_term (L);
+    VOLK_Term **tp = allocate_term (L);
 
-    *tp = LSUP_iriref_new_abs (root, iri);
+    *tp = VOLK_iriref_new_abs (root, iri);
     LUA_NLCHECK (*tp, "Error creating term.");
 
     return 1;
@@ -69,13 +94,13 @@ static int l_new_iriref_abs (lua_State *L)
 
 static int l_new_iriref_rel (lua_State *L)
 {
-    LSUP_Term
+    VOLK_Term
         *root = check_term (L),
-        *iri = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
+        *iri = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
 
-    LSUP_Term **tp = allocate_term (L);
+    VOLK_Term **tp = allocate_term (L);
 
-    *tp = LSUP_iriref_new_rel (root, iri);
+    *tp = VOLK_iriref_new_rel (root, iri);
     LUA_NLCHECK (*tp, "Error creating term.");
 
     return 1;
@@ -95,16 +120,16 @@ static int l_new_lit (lua_State *L)
         *dtype_str = lua_tostring (L, 2);
     const char *lang = lua_tostring (L, 3);
 
-    LSUP_Term **tp = allocate_term (L);
-    LSUP_Term *dtype;
+    VOLK_Term **tp = allocate_term (L);
+    VOLK_Term *dtype;
 
     if (dtype_str) {
         // TODO check memory leak.
-        dtype = LSUP_iriref_new (dtype_str);
-        *tp = LSUP_literal_new (data, dtype);
+        dtype = VOLK_iriref_new (dtype_str);
+        *tp = VOLK_literal_new (data, dtype);
     }
-    else if (lang) *tp = LSUP_lt_literal_new (data, (char *)lang);
-    else *tp = LSUP_literal_new (data, NULL);
+    else if (lang) *tp = VOLK_lt_literal_new (data, (char *)lang);
+    else *tp = VOLK_literal_new (data, NULL);
 
     LUA_NLCHECK (*tp, "Error creating term.");
 
@@ -116,9 +141,9 @@ static int l_new_bnode (lua_State *L)
 {
     const char *data = lua_tostring (L, 1);
 
-    LSUP_Term **tp = allocate_term (L);
+    VOLK_Term **tp = allocate_term (L);
 
-    *tp = LSUP_bnode_new (data);
+    *tp = VOLK_bnode_new (data);
     LUA_NLCHECK (*tp, "Error creating term.");
 
     return 1;
@@ -127,11 +152,11 @@ static int l_new_bnode (lua_State *L)
 
 static int l_new_copy (lua_State *L)
 {
-    LSUP_Term *src = check_term (L);
+    VOLK_Term *src = check_term (L);
 
-    LSUP_Term **tp = allocate_term (L);
+    VOLK_Term **tp = allocate_term (L);
 
-    *tp = LSUP_term_copy (src);
+    *tp = VOLK_term_copy (src);
     LUA_NLCHECK (*tp, "Error creating term.");
 
     return 1;
@@ -143,11 +168,11 @@ static int l_new_copy (lua_State *L)
  */
 static int l_term_equals (lua_State *L)
 {
-    LSUP_Term
+    VOLK_Term
         *t1 = check_term (L),
-        *t2 = *(LSUP_Term **)luaL_checkudata (L, 2, "LSUP.Term");
+        *t2 = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
 
-    lua_pushboolean (L, LSUP_term_equals (t1, t2));
+    lua_pushboolean (L, VOLK_term_equals (t1, t2));
 
     return 1;
 }
@@ -155,10 +180,10 @@ static int l_term_equals (lua_State *L)
 
 static int l_term_gc (lua_State *L)
 {
-    LSUP_Term **tp = luaL_checkudata(L, 1, "LSUP.Term");
+    VOLK_Term **tp = luaL_checkudata(L, 1, "VOLK.Term");
     LOG_TRACE ("Garbage collecting term @%p", *tp);
 
-    LSUP_term_free (*tp);
+    VOLK_term_free (*tp);
     *tp = NULL;
 
     return 0;
@@ -168,11 +193,11 @@ static int l_term_gc (lua_State *L)
 /*
 static int l_term_to_string (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
+    VOLK_Term *t = check_term (L);
     char *nt_term = NULL;
 
     CHECK (nt_codec.encode_term (t, NULL, &nt_term), fail);
-    lua_pushfstring (L, "LSUP.Term @%p %s", t, nt_term);
+    lua_pushfstring (L, "VOLK.Term @%p %s", t, nt_term);
 
     return 1;
 
@@ -185,7 +210,7 @@ fail:
 
 static int l_term_to_n3 (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
+    VOLK_Term *t = check_term (L);
     char *nt_term = NULL;
 
     CHECK (nt_codec.encode_term (t, &nt_term), fail);
@@ -226,7 +251,7 @@ static int l_term_get_attr (lua_State *L)
 
 static int get_data (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
+    VOLK_Term *t = check_term (L);
     lua_pushstring (L, t->data);
 
     return 1;
@@ -235,7 +260,7 @@ static int get_data (lua_State *L)
 
 static int get_type (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
+    VOLK_Term *t = check_term (L);
     lua_pushinteger (L, t->type);
 
     return 1;
@@ -244,8 +269,8 @@ static int get_type (lua_State *L)
 
 static int get_iriref_prefix (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
-    lua_pushstring (L, LSUP_iriref_prefix (t));
+    VOLK_Term *t = check_term (L);
+    lua_pushstring (L, VOLK_iriref_prefix (t));
 
     return 1;
 }
@@ -253,8 +278,8 @@ static int get_iriref_prefix (lua_State *L)
 
 static int get_iriref_path (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
-    lua_pushstring (L, LSUP_iriref_path (t));
+    VOLK_Term *t = check_term (L);
+    lua_pushstring (L, VOLK_iriref_path (t));
 
     return 1;
 }
@@ -262,8 +287,8 @@ static int get_iriref_path (lua_State *L)
 
 static int get_iriref_frag (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
-    lua_pushstring (L, LSUP_iriref_frag (t));
+    VOLK_Term *t = check_term (L);
+    lua_pushstring (L, VOLK_iriref_frag (t));
 
     return 1;
 }
@@ -272,8 +297,8 @@ static int get_iriref_frag (lua_State *L)
 static int get_lit_datatype (lua_State *L)
 {
     printf ("Getting datatype.\n");
-    LSUP_Term *t = check_term (L);
-    if (!LSUP_IS_LITERAL (t))
+    VOLK_Term *t = check_term (L);
+    if (!VOLK_IS_LITERAL (t))
         return luaL_error (L, "Term is not a literal.", 2);
 
     lua_pushstring (L, t->datatype->data);
@@ -284,10 +309,10 @@ static int get_lit_datatype (lua_State *L)
 
 static int get_lit_lang (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
-    if (!LSUP_IS_LITERAL (t))
+    VOLK_Term *t = check_term (L);
+    if (!VOLK_IS_LITERAL (t))
         return luaL_error (L, "Term is not a literal.", 2);
-    if (t->type != LSUP_TERM_LT_LITERAL) return 0;
+    if (t->type != VOLK_TERM_LT_LITERAL) return 0;
 
     lua_pushstring (L, t->lang);
 
@@ -297,9 +322,9 @@ static int get_lit_lang (lua_State *L)
 
 static int get_hash (lua_State *L)
 {
-    LSUP_Term *t = check_term (L);
+    VOLK_Term *t = check_term (L);
 
-    lua_pushinteger (L, LSUP_term_hash (t));
+    lua_pushinteger (L, VOLK_term_hash (t));
 
     return 1;
 }
@@ -321,23 +346,23 @@ static int l_term_set_attr (lua_State *L)
 
 static int lmap_iter_next (lua_State *L)
 {
-    LSUP_LinkMapIterator *it =
-        *(LSUP_LinkMapIterator **)lua_touserdata (L, lua_upvalueindex (1));
+    VOLK_LinkMapIterator *it =
+        *(VOLK_LinkMapIterator **)lua_touserdata (L, lua_upvalueindex (1));
 
-    LSUP_Term **link_p = (LSUP_Term **)lua_newuserdata (L, sizeof *link_p);
+    VOLK_Term **link_p = (VOLK_Term **)lua_newuserdata (L, sizeof *link_p);
     *link_p = NULL;
-    luaL_getmetatable (L, "LSUP.Term");
+    luaL_getmetatable (L, "VOLK.Term");
     lua_setmetatable (L, -2);
 
-    LSUP_TermSet *ts = NULL;
-    LSUP_Term *tmp = NULL;
-    LSUP_rc rc = LSUP_link_map_next (it, &tmp, &ts);
+    VOLK_TermSet *ts = NULL;
+    VOLK_Term *tmp = NULL;
+    VOLK_rc rc = VOLK_link_map_next (it, &tmp, &ts);
 
-    if (rc != LSUP_OK) {
-        if (rc == LSUP_END) return 0;
+    if (rc != VOLK_OK) {
+        if (rc == VOLK_END) return 0;
         else LUA_PCHECK (rc, "Error iterating over link map");
     }
-    *link_p = LSUP_term_copy (tmp);
+    *link_p = VOLK_term_copy (tmp);
     LUA_NLCHECK (*link_p, "Error allocating term.");
 
     LUA_PCHECK (term_set_to_table (L, ts), "Error generating term set");
@@ -355,13 +380,13 @@ static int lmap_iter_next (lua_State *L)
 static int l_lmap_iter_init (lua_State *L)
 {
     stack_dump (L, "beginning of LMap iter init fn");
-    LSUP_LinkMap *lm = *(LSUP_LinkMap **)luaL_checkudata(L, 1, "LSUP.LinkMap");
+    VOLK_LinkMap *lm = *(VOLK_LinkMap **)luaL_checkudata(L, 1, "VOLK.LinkMap");
 
-    LSUP_LinkMapIterator **lmit_p =
-        (LSUP_LinkMapIterator  **)lua_newuserdata (L, sizeof *lmit_p);
-    *lmit_p = LSUP_link_map_iter_new (lm);
+    VOLK_LinkMapIterator **lmit_p =
+        (VOLK_LinkMapIterator  **)lua_newuserdata (L, sizeof *lmit_p);
+    *lmit_p = VOLK_link_map_iter_new (lm);
     LUA_NLCHECK (*lmit_p, "Error creating Link map iterator.");
-    luaL_getmetatable (L, "LSUP.LMapIterator");
+    luaL_getmetatable (L, "VOLK.LMapIterator");
     lua_setmetatable (L, -2);
 
     lua_pushcclosure (L, lmap_iter_next, 1);
@@ -373,13 +398,13 @@ static int l_lmap_iter_init (lua_State *L)
 
 static int link_map_gc (lua_State *L)
 {
-    LSUP_LinkMap **lm_p = lua_touserdata (L, 1);
+    VOLK_LinkMap **lm_p = lua_touserdata (L, 1);
     LOG_DEBUG ("Garbage collecting link map @%p", *lm_p);
     // FIXME This is to prevent a double-free on shutdown.
     // Must find the culprit instead.
     if (UNLIKELY (!lm_p || !*lm_p)) return 0;
 
-    LSUP_link_map_free (*lm_p);
+    VOLK_link_map_free (*lm_p);
     *lm_p = NULL;
 
     return 0;
@@ -388,9 +413,9 @@ static int link_map_gc (lua_State *L)
 
 static int lmap_iter_gc (lua_State *L)
 {
-    LSUP_LinkMapIterator *it = *(LSUP_LinkMapIterator **)lua_touserdata (L, 1);
+    VOLK_LinkMapIterator *it = *(VOLK_LinkMapIterator **)lua_touserdata (L, 1);
     LOG_DEBUG ("Garbage collecting link map iterator @%p", it);
-    LSUP_link_map_iter_free (it);
+    VOLK_link_map_iter_free (it);
 
     return 0;
 }
@@ -452,22 +477,22 @@ static const luaL_Reg term_lib_meth [] = {
 
 
 static const LEnumConst term_enums[] = {
-    {"TYPE_IRIREF", LSUP_TERM_IRIREF},
-    {"TYPE_LITERAL", LSUP_TERM_LITERAL},
-    {"TYPE_LT_LITERAL", LSUP_TERM_LT_LITERAL},
-    {"TYPE_BNODE", LSUP_TERM_BNODE},
+    {"TYPE_IRIREF", VOLK_TERM_IRIREF},
+    {"TYPE_LITERAL", VOLK_TERM_LITERAL},
+    {"TYPE_LT_LITERAL", VOLK_TERM_LT_LITERAL},
+    {"TYPE_BNODE", VOLK_TERM_BNODE},
 
-    {"LINK_INBOUND", LSUP_LINK_INBOUND},
-    {"LINK_OUTBOUND", LSUP_LINK_OUTBOUND},
-    {"LINK_EDGE", LSUP_LINK_EDGE},
+    {"LINK_INBOUND", VOLK_LINK_INBOUND},
+    {"LINK_OUTBOUND", VOLK_LINK_OUTBOUND},
+    {"LINK_EDGE", VOLK_LINK_EDGE},
 
     {NULL, 0}
 };
 
 
 static const LStringConst term_strings[] = {
-    {"RDF_TYPE", LSUP_RDF_TYPE},
-    {"RDF_TYPE_NS", LSUP_RDF_TYPE_NS},
+    {"RDF_TYPE", VOLK_RDF_TYPE},
+    {"RDF_TYPE_NS", VOLK_RDF_TYPE_NS},
     {"DEFAULT_DTYPE", DEFAULT_DTYPE},
     {"DEFAULT_DTYPE_NS", DEFAULT_DTYPE_NS},
     {"DEFAULT_CTX", DEFAULT_CTX_LABEL},
@@ -476,10 +501,10 @@ static const LStringConst term_strings[] = {
 };
 
 
-int luaopen_lsup_term (lua_State *L)
+int luaopen_volksdata_term (lua_State *L)
 {
-    LSUP_init();  // This is idempotent: no problem calling it multiple times.
-    luaL_newmetatable (L, "LSUP.Term");
+    VOLK_init();  // This is idempotent: no problem calling it multiple times.
+    luaL_newmetatable (L, "VOLK.Term");
     luaL_setfuncs (L, term_lib_meth, 0);
 
     // Getters table.
@@ -495,14 +520,14 @@ int luaopen_lsup_term (lua_State *L)
      * Metatables for ancillary types.
      */
     // Link map.
-    luaL_newmetatable (L, "LSUP.LinkMap");
+    luaL_newmetatable (L, "VOLK.LinkMap");
     lua_pushcfunction (L, link_map_gc);
     lua_setfield (L, -2, "__gc");
     lua_pushcfunction (L, l_lmap_iter_init);
     lua_setfield (L, -2, "__pairs");
 
     // Link map iterator.
-    luaL_newmetatable (L, "LSUP.LMapIterator");
+    luaL_newmetatable (L, "VOLK.LMapIterator");
     lua_pushcfunction (L, lmap_iter_gc);
     lua_setfield (L, -2, "__gc");
 

+ 33 - 33
src/lua_triple.c

@@ -1,4 +1,4 @@
-#include "lua_lsup.h"
+#include "lua_volksdata.h"
 
 
 /*
@@ -7,18 +7,18 @@
 
 static int l_triple_new (lua_State *L)
 {
-    LSUP_Triple **trp_p = lua_newuserdatauv (L, sizeof (*trp_p), 1);
-    luaL_getmetatable (L, "LSUP.Triple");
+    VOLK_Triple **trp_p = lua_newuserdatauv (L, sizeof (*trp_p), 1);
+    luaL_getmetatable (L, "VOLK.Triple");
     lua_setmetatable (L, -2);
-    LSUP_Term
-        *s = *(LSUP_Term **)luaL_checkudata(L, 1, "LSUP.Term"),
-        *p = *(LSUP_Term **)luaL_checkudata(L, 2, "LSUP.Term"),
-        *o = *(LSUP_Term **)luaL_checkudata(L, 3, "LSUP.Term");
-
-    *trp_p = LSUP_triple_new (
-            LSUP_term_copy (s),
-            LSUP_term_copy (p),
-            LSUP_term_copy (o));
+    VOLK_Term
+        *s = *(VOLK_Term **)luaL_checkudata(L, 1, "VOLK.Term"),
+        *p = *(VOLK_Term **)luaL_checkudata(L, 2, "VOLK.Term"),
+        *o = *(VOLK_Term **)luaL_checkudata(L, 3, "VOLK.Term");
+
+    *trp_p = VOLK_triple_new (
+            VOLK_term_copy (s),
+            VOLK_term_copy (p),
+            VOLK_term_copy (o));
     if (!*trp_p) return luaL_error (L, "Error while creating a triple!");
 
     return 1;
@@ -31,8 +31,8 @@ static int l_triple_new (lua_State *L)
 
 static int l_triple_gc (lua_State *L)
 {
-    LSUP_Triple *trp = check_triple (L);
-    if (trp) LSUP_triple_free (trp);
+    VOLK_Triple *trp = check_triple (L);
+    if (trp) VOLK_triple_free (trp);
 
     return 0;
 }
@@ -49,16 +49,16 @@ static int l_triple_gc (lua_State *L)
  */
 static int l_triple_get_term (lua_State *L)
 {
-    const LSUP_Triple *trp = check_triple (L);
+    const VOLK_Triple *trp = check_triple (L);
     const char pos = luaL_checkstring (L, 2)[0];
-    LSUP_TriplePos pn;
+    VOLK_TriplePos pn;
     if (pos == 's') pn = TRP_POS_S;
     else if (pos == 'p') pn = TRP_POS_P;
     else if (pos == 'o') pn = TRP_POS_O;
     else return luaL_error (L, "Out of range position: %c.", pos);
 
-    LSUP_Term **tp = allocate_term (L);
-    *tp = LSUP_term_copy (LSUP_triple_pos (trp, pn));
+    VOLK_Term **tp = allocate_term (L);
+    *tp = VOLK_term_copy (VOLK_triple_pos (trp, pn));
     if (!*tp) return luaL_error (L, "Error while copying a triple term!");
 
     return 1;
@@ -67,20 +67,20 @@ static int l_triple_get_term (lua_State *L)
 
 static int l_triple_set_term (lua_State *L)
 {
-    LSUP_Triple *trp = check_triple (L);
+    VOLK_Triple *trp = check_triple (L);
     const char pos = luaL_checkstring (L, 2)[0];
-    const LSUP_Term *t = *(LSUP_Term **)luaL_checkudata(L, 3, "LSUP.Term");
+    const VOLK_Term *t = *(VOLK_Term **)luaL_checkudata(L, 3, "VOLK.Term");
 
-    LSUP_Term *new_t = LSUP_term_copy (t);
+    VOLK_Term *new_t = VOLK_term_copy (t);
 
     if (pos == 's') {
-        LSUP_term_free (trp->s);
+        VOLK_term_free (trp->s);
         trp->s = new_t;
     } else if (pos == 'p') {
-        LSUP_term_free (trp->p);
+        VOLK_term_free (trp->p);
         trp->p = new_t;
     } else if (pos == 'o') {
-        LSUP_term_free (trp->o);
+        VOLK_term_free (trp->o);
         trp->o = new_t;
     } else return luaL_error(L, "Out of range position: %c.", pos);
 
@@ -90,16 +90,16 @@ static int l_triple_set_term (lua_State *L)
 
 static int l_triple_copy_term (lua_State *L)
 {
-    const LSUP_Triple *trp = check_triple (L);
+    const VOLK_Triple *trp = check_triple (L);
     const char pos = luaL_checkstring (L, 2)[0];
-    LSUP_TriplePos pn;
+    VOLK_TriplePos pn;
     if (pos == 's') pn = TRP_POS_S;
     else if (pos == 'p') pn = TRP_POS_P;
     else if (pos == 'o') pn = TRP_POS_O;
     else return luaL_error(L, "Copy: Out of range position: %c.", pos);
 
-    LSUP_Term **tp = allocate_term (L);
-    *tp = LSUP_term_copy (LSUP_triple_pos (trp, pn));
+    VOLK_Term **tp = allocate_term (L);
+    *tp = VOLK_term_copy (VOLK_triple_pos (trp, pn));
     if (!*tp) return luaL_error (L, "Error while copying a triple term!");
 
     return 1;
@@ -108,12 +108,12 @@ static int l_triple_copy_term (lua_State *L)
 
 static int l_triple_to_n3 (lua_State *L)
 {
-    const LSUP_Triple *trp = check_triple (L);
+    const VOLK_Triple *trp = check_triple (L);
     char *nt_term = NULL;
 
     for (int i = TRP_POS_S; i <= TRP_POS_O; i++) {
         CHECK (nt_codec.encode_term (
-                    LSUP_triple_pos (trp, i), &nt_term), fail);
+                    VOLK_triple_pos (trp, i), &nt_term), fail);
         lua_pushstring (L, nt_term);
         lua_pushstring (L, " ");
     }
@@ -159,10 +159,10 @@ static const LEnumConst triple_enums[] = {
 };
 
 
-int luaopen_lsup_triple (lua_State *L)
+int luaopen_volksdata_triple (lua_State *L)
 {
-    LSUP_init();  // This is idempotent: no problem calling it multiple times.
-    luaL_newmetatable (L, "LSUP.Triple");
+    VOLK_init();  // This is idempotent: no problem calling it multiple times.
+    luaL_newmetatable (L, "VOLK.Triple");
     lua_pushvalue (L, -1);
 
     // MT

+ 1 - 1
src/lua_lsup.c → src/lua_volksdata.c

@@ -1,4 +1,4 @@
-#include "lua_lsup.h"
+#include "lua_volksdata.h"
 
 void push_int_const (lua_State *L, const LEnumConst *list) {
     for (int i = 0; list[i].k; i++) {

+ 14 - 14
src/lua_lsup.h → src/lua_volksdata.h

@@ -1,15 +1,15 @@
 #include <lua.h>
 #include <lauxlib.h>
 
-#include "lsup_rdf.h"
+#include "volksdata.h"
 
-#ifndef _LUA_LSUP_H
-#define _LUA_LSUP_H
+#ifndef _LUA_VOLK_H
+#define _LUA_VOLK_H
 
-/// Raise Lua error including LSUP error message on negative rc.
+/// Raise Lua error including VOLK error message on negative rc.
 #define LUA_PCHECK(exp, message) do {\
-    if (UNLIKELY ((exp) < LSUP_OK)) \
-        return luaL_error (L, "%s: %s", message, LSUP_strerror (exp)); \
+    if (UNLIKELY ((exp) < VOLK_OK)) \
+        return luaL_error (L, "%s: %s", message, VOLK_strerror (exp)); \
 } while (0)
 
 #define LUA_NLCHECK(exp, ...) do {\
@@ -22,13 +22,13 @@
  */
 
 #define check_term(L) \
-    *(LSUP_Term **)luaL_checkudata(L, 1, "LSUP.Term")
+    *(VOLK_Term **)luaL_checkudata(L, 1, "VOLK.Term")
 
 #define check_triple(L) \
-    *(LSUP_Triple **)luaL_checkudata(L, 1, "LSUP.Triple")
+    *(VOLK_Triple **)luaL_checkudata(L, 1, "VOLK.Triple")
 
 #define check_graph(L) \
-    *(LSUP_Graph **)luaL_checkudata(L, 1, "LSUP.Graph")
+    *(VOLK_Graph **)luaL_checkudata(L, 1, "VOLK.Graph")
 
 
 /// Enum (int) constants to be passed to the module.
@@ -52,10 +52,10 @@ void push_string_const (lua_State *L, const LStringConst *list);
 int l_nsmap_new (lua_State *L);
 
 /// Allocate space for a term object.
-LSUP_Term **allocate_term (lua_State *L);
+VOLK_Term **allocate_term (lua_State *L);
 
-/// Convert a LSUP_TermSet to a table and push it.
-LSUP_rc
-term_set_to_table (lua_State *L, LSUP_TermSet *ts);
+/// Convert a VOLK_TermSet to a table and push it.
+VOLK_rc
+term_set_to_table (lua_State *L, VOLK_TermSet *ts);
 
-#endif  // _LUA_LSUP_H
+#endif  // _LUA_VOLK_H

+ 7 - 7
test.lua

@@ -1,8 +1,8 @@
-term = require "lsup.term"
-triple = require "lsup.triple"
-graph = require "lsup.graph"
-store = require "lsup.store"
-namespace = require "lsup.namespace"
+term = require "volksdata.term"
+triple = require "volksdata.triple"
+graph = require "volksdata.graph"
+store = require "volksdata.store"
+namespace = require "volksdata.namespace"
 
 ---[[
 t1 = term.new_bnode()
@@ -23,7 +23,7 @@ triples = {
     triple.new (t1, t2, t5),
 }
 
-mdb_store = store.new(store.MDB, "file:///tmp/lsup_lua.db", true)
+mdb_store = store.new(store.MDB, "file:///tmp/volksdata_lua.db", true)
 print(("MDB store: %s"):format(mdb_store))
 local gr1 = graph.new(mdb_store)
 
@@ -72,7 +72,7 @@ assert(nsm_map.ns1 == "urn:ns:1#")
 assert(nsm_map.ns2 == "urn:ns:2#")
 assert(nsm_map.ns3 == "urn:ns:3#")
 
-local mdb_store_ns = store.new(store.MDB, "file:///tmp/lsup_nsm.db", true)
+local mdb_store_ns = store.new(store.MDB, "file:///tmp/volksdata_nsm.db", true)
 
 local mdb_gr2 = graph.new(mdb_store_ns, "ns1:gr2", nsm)
 local mdb_gr3 = graph.new(mdb_store_ns, "ns1:gr3", nsm)

+ 6 - 5
lsup-scm-1.rockspec → volksdata-scm-1.rockspec

@@ -1,8 +1,8 @@
-package = "lsup"
+package = "volksdata"
 version = "scm-1"
 
 source = {
-   url = "git://git.knowledgetx.com/scossu/lsup_lua.git",
+   url = "git://git.knowledgetx.com/scossu/volksdata_lua.git",
    branch = "master",
    tag = "HEAD",
 }
@@ -10,13 +10,14 @@ source = {
 description = {
    summary = "Compact, minimalistic RDF library and persistent store.",
    detailed = [[
-      `lsup_rdf` is an embedded library to manipulate and permanently store
+      Volksdata is an embedded library to manipulate and permanently store
       Linked Data. It handles terms, triples, graphs, and has in-memory and
       persistent storage back ends. It can encode and decode Turtle and N3
       syntax.
    ]],
-   homepage = "http://git.knowledgetx.com/scossu/lsup_lua",
-   license = "https://git.knowledgetx.com/scossu/lsup_lua/src/master/LICENSE"
+   homepage = "http://git.knowledgetx.com/scossu/volksdata_lua",
+   license =
+       "https://git.knowledgetx.com/scossu/volksdata_lua/src/master/LICENSE"
 }
 
 dependencies = {