Browse Source

Use Makefile.

scossu 4 days ago
parent
commit
fe435775c3
9 changed files with 309 additions and 20 deletions
  1. 1 1
      include/core.h
  2. 39 0
      lsup_rdf-scm.rockspec
  3. 20 0
      lua/Makefile
  4. 114 0
      lua/lua_triple.c
  5. 0 0
      lua/src/lua_lsup.c
  6. 0 0
      lua/src/lua_lsup.h
  7. 2 2
      lua/src/lua_namespace.c
  8. 19 17
      lua/src/lua_term.c
  9. 114 0
      lua/src/lua_triple.c

+ 1 - 1
include/core.h

@@ -106,7 +106,7 @@ typedef int LSUP_rc;
  * with a different form or value. The caller should find the value of the
  * existing resource to be different than the one that was attempted to store.
  * If this is returned from the iteration of multiple updates, it means that
- * other resources in the loop may have changed state and the operation as a
+ * some resources in the loop may have changed state and the operation as a
  * whole completed successfully.
  *
  * The error-level counterpart to this is #LSUP_CONFLICT_ERR.

+ 39 - 0
lsup_rdf-scm.rockspec

@@ -0,0 +1,39 @@
+package = "lsup_rdf"
+version = "scm"
+source = {
+    url = "./"
+   --url = "git://git.knowledgetx.com/scossu/lsup_rdf",
+   --tag = "scm",
+}
+description = {
+   summary = "Super-compact, embedded RDF library and permanent store.",
+   detailed = [[
+      `lsup_rdf` is an embedded library to manipulate and permanently store
+      Linked Data. It handles terms, triples, graphs, and has an in-memory and
+      a filesystem-based storage back ends.
+   ]],
+   homepage = "http://git.knowledgetx.com/scossu/lsup_rdf",
+   license = "https://git.knowledgetx.com/scossu/lsup_rdf/src/master/LICENSE"
+}
+dependencies = {
+   "lua >= 5.4, < 6",
+}
+build = {
+   type = "builtin",
+   modules = {
+      lsup = {
+         sources = {
+             "lua/lua_namespace.c",
+             "lua/lua_term.c",
+             "lua/lua_triple.c",
+             --"lua/lua_graph.c",
+             "lua/lua_lsup.c",
+         },
+         defines = {},
+         libraries = {"lsuprdf"},
+         incdirs = {"./include", "./ext/log/src", "./ext/hashmap"},
+         libdirs = {}
+      }
+   },
+   --copy_directories = {}
+}

+ 20 - 0
lua/Makefile

@@ -0,0 +1,20 @@
+.DEFAULT_GOAL := lib
+
+INCLUDE = -I/usr/local/include/lsup
+CFLAGS = -shared -Wall -fPIC $(INCLUDE)
+LDFLAGS = -L/usr/local/lib -llua -llsuprdf_dbg
+
+LUAC_SRC = $(wildcard src/*.c)
+#OBJ = $(patsubst lua/%, lua/build/, $(patsubst %.c, %.o, $(LUAC_SRC)))
+OBJ = $(patsubst src/%.c, lib/%.so, $(LUAC_SRC))
+S_OBJ = lsup.so
+
+.PHONY: lib
+lib: $(OBJ)
+
+lib/%.so: src/%.c
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+.PHONY: clean
+clean:
+	rm -rf build/* lib/*.so

+ 114 - 0
lua/lua_triple.c

@@ -0,0 +1,114 @@
+#include "lua_lsup.h"
+
+#define check_triple(L) \
+    *(LSUP_Triple **)luaL_checkudata(L, 1, "LSUP.Triple")
+
+
+/*
+ * Factory methods.
+ */
+
+static int new (lua_State *L)
+{
+    LSUP_Triple **trp_p = lua_newuserdatauv (L, sizeof (*trp_p), 1);
+    luaL_getmetatable (L, "LSUP.Triple");
+    LSUP_Term
+        *s = *(LSUP_Term **)luaL_checkudata(L, 2, "LSUP.Term"),
+        *p = *(LSUP_Term **)luaL_checkudata(L, 3, "LSUP.Term"),
+        *o = *(LSUP_Term **)luaL_checkudata(L, 4, "LSUP.Term");
+
+    lua_setmetatable (L, -4);
+
+    *trp_p = LSUP_triple_new (s, p, o);
+    if (!*trp_p) luaL_error (L, "Error while creating a triple!");
+
+    return 1;
+}
+
+
+/*
+ * Class methods.
+ */
+
+static int gc (lua_State *L)
+{
+    LSUP_Triple *trp = check_triple (L);
+    if (trp) LSUP_triple_free (trp);
+
+    return 0;
+}
+
+
+static int get_term (lua_State *L)
+{
+    const LSUP_Triple *trp = check_triple (L);
+    const int pos = luaL_checkinteger (L, 2);
+    if (pos < TRP_POS_S || pos > TRP_POS_O)
+        luaL_error(L, "Out of range position: %d.", pos);
+
+    lua_pushlightuserdata (L, LSUP_triple_pos (trp, (LSUP_TriplePos)pos));
+
+    return 1;
+}
+
+
+static int set_term (lua_State *L)
+{
+    LSUP_Triple *trp = check_triple (L);
+    const int pos = luaL_checkinteger (L, 2);
+    const LSUP_Term *t = *(LSUP_Term **)luaL_checkudata(L, 3, "LSUP.Term");
+
+    LSUP_Term *new_t = LSUP_term_copy (t);
+
+    if (pos == TRP_POS_S) {
+        LSUP_term_free (trp->s);
+        trp->s = new_t;
+    } else if (pos == TRP_POS_P) {
+        LSUP_term_free (trp->p);
+        trp->p = new_t;
+    } else if (pos == TRP_POS_O) {
+        LSUP_term_free (trp->o);
+        trp->o = new_t;
+    } else return luaL_error(L, "Out of range position: %d.", pos);
+
+    return 1;
+}
+
+
+/*
+ * Library setup.
+ */
+
+static const struct luaL_Reg triple_lib_fn [] = {
+    {"new", new},
+    {NULL}
+};
+
+
+static const struct luaL_Reg triple_lib_meth [] = {
+    {"__gc", gc},
+
+    {NULL}
+};
+
+
+int luaopen_triple (lua_State *L)
+{
+    luaL_newmetatable (L, "LSUP.Triple");
+    lua_pushvalue (L, -1);
+    lua_setfield (L, -2, "__index");
+    luaL_setfuncs (L, triple_lib_meth, 0);
+
+    // Enums
+    lua_pushvalue (L, TRP_POS_S);
+    lua_setfield (L, -1, "TRP_POS_S");
+    lua_pushvalue (L, TRP_POS_P);
+    lua_setfield (L, -1, "TRP_POS_P");
+    lua_pushvalue (L, TRP_POS_O);
+    lua_setfield (L, -1, "TRP_POS_O");
+
+    luaL_newlib (L, triple_lib_fn);
+
+    return 1;
+}
+

+ 0 - 0
lua/lua_lsup.c → lua/src/lua_lsup.c


+ 0 - 0
lua/lua_lsup.h → lua/src/lua_lsup.h


+ 2 - 2
lua/lua_namespace.c → lua/src/lua_namespace.c

@@ -126,7 +126,7 @@ static int l_nsmap_denormalize_uri (lua_State *L)
 }
 
 
-static int l_nsmap_dump (lua_State *L)
+static int l_nsmap_iter (lua_State *L)
 {
     LSUP_NSMap *nsm = check_nsm (L);
 
@@ -155,7 +155,7 @@ static const struct luaL_Reg nsmap_lib_meth [] = {
     {"get_pfx", l_nsmap_get_pfx},
     {"normalize_uri", l_nsmap_normalize_uri},
     {"denormalize_uri", l_nsmap_denormalize_uri},
-    //{"dump", l_nsmap_dump},
+    //{"iter", l_nsmap_iter},
 
     {NULL}
 };

+ 19 - 17
lua/lua_term.c → lua/src/lua_term.c

@@ -71,10 +71,11 @@ static int l_lit_new (lua_State *L)
     const char *lang = luaL_checkstring (L, 3);
 
     LSUP_Term **tp = allocate_term (L);
+    LSUP_Term *dtype;
 
     if (lang) *tp = LSUP_lt_literal_new (data, (char *)lang);
     else {
-        LSUP_Term *dtype = (dtype) ? LSUP_iriref_new (dtype_str, NULL) : NULL;
+        dtype = (dtype_str) ? LSUP_iriref_new (dtype_str, NULL) : NULL;
         *tp = LSUP_literal_new (data, dtype);
     }
 
@@ -110,20 +111,6 @@ static int new_copy (lua_State *L)
 }
 
 
-static int new_from_buffer (lua_State *L)
-{
-    const LSUP_Buffer *sterm = *(LSUP_Buffer **)luaL_checkudata (
-            L, 1, "LSUP.Buffer");
-
-    LSUP_Term **tp = allocate_term (L);
-
-    *tp = LSUP_term_new_from_buffer (sterm);
-    if (!*tp) luaL_error (L, "Error while creating a term!");
-
-    return 1;
-}
-
-
 /*
  * Class methods.
  */
@@ -158,6 +145,7 @@ static int get_hash (lua_State *L)
 }
 
 
+/*
 static int serialize (lua_State *L)
 {
     LSUP_Term *t = check_term (L);
@@ -170,6 +158,17 @@ static int serialize (lua_State *L)
 
     return 1;
 }
+*/
+
+
+static int to_string (lua_State *L)
+{
+    LSUP_Term *t = check_term (L);
+
+    lua_pushstring (L, t->data);
+
+    return 1;
+}
 
 
 /*
@@ -276,7 +275,7 @@ static int get_lit_lang (lua_State *L)
 
 // Very simple for now.
 static int set_attr (lua_State *L)
-{ luaL_error (L, "Direct attribute setting is not allowed for this type."); }
+{ return luaL_error (L, "Direct setting is not allowed for this type.", 2); }
 
 
 /*
@@ -313,18 +312,21 @@ static const luaL_Reg term_getters [] = {
 };
 
 
+/*
 static const luaL_Reg term_setters [] = {
     {NULL}
 };
+*/
 
 static const luaL_Reg term_lib_meth [] = {
     {"__eq", equals},
     {"__gc", gc},
     {"__index", get_attr},
+    {"__tostring", to_string},
     {"__newindex", set_attr},
 
     {"hash", get_hash},
-    {"serialize", serialize},
+    //{"serialize", serialize},
 
     {NULL}
 };

+ 114 - 0
lua/src/lua_triple.c

@@ -0,0 +1,114 @@
+#include "lua_lsup.h"
+
+#define check_triple(L) \
+    *(LSUP_Triple **)luaL_checkudata(L, 1, "LSUP.Triple")
+
+
+/*
+ * Factory methods.
+ */
+
+static int new (lua_State *L)
+{
+    LSUP_Triple **trp_p = lua_newuserdatauv (L, sizeof (*trp_p), 1);
+    luaL_getmetatable (L, "LSUP.Triple");
+    LSUP_Term
+        *s = *(LSUP_Term **)luaL_checkudata(L, 2, "LSUP.Term"),
+        *p = *(LSUP_Term **)luaL_checkudata(L, 3, "LSUP.Term"),
+        *o = *(LSUP_Term **)luaL_checkudata(L, 4, "LSUP.Term");
+
+    lua_setmetatable (L, -4);
+
+    *trp_p = LSUP_triple_new (s, p, o);
+    if (!*trp_p) luaL_error (L, "Error while creating a triple!");
+
+    return 1;
+}
+
+
+/*
+ * Class methods.
+ */
+
+static int gc (lua_State *L)
+{
+    LSUP_Triple *trp = check_triple (L);
+    if (trp) LSUP_triple_free (trp);
+
+    return 0;
+}
+
+
+static int get_term (lua_State *L)
+{
+    const LSUP_Triple *trp = check_triple (L);
+    const int pos = luaL_checkinteger (L, 2);
+    if (pos < TRP_POS_S || pos > TRP_POS_O)
+        luaL_error(L, "Out of range position: %d.", pos);
+
+    lua_pushlightuserdata (L, LSUP_triple_pos (trp, (LSUP_TriplePos)pos));
+
+    return 1;
+}
+
+
+static int set_term (lua_State *L)
+{
+    LSUP_Triple *trp = check_triple (L);
+    const int pos = luaL_checkinteger (L, 2);
+    const LSUP_Term *t = *(LSUP_Term **)luaL_checkudata(L, 3, "LSUP.Term");
+
+    LSUP_Term *new_t = LSUP_term_copy (t);
+
+    if (pos == TRP_POS_S) {
+        LSUP_term_free (trp->s);
+        trp->s = new_t;
+    } else if (pos == TRP_POS_P) {
+        LSUP_term_free (trp->p);
+        trp->p = new_t;
+    } else if (pos == TRP_POS_O) {
+        LSUP_term_free (trp->o);
+        trp->o = new_t;
+    } else luaL_error(L, "Out of range position: %d.", pos);
+
+    return 1;
+}
+
+
+/*
+ * Library setup.
+ */
+
+static const struct luaL_Reg triple_lib_fn [] = {
+    {"new", new},
+    {NULL}
+};
+
+
+static const struct luaL_Reg triple_lib_meth [] = {
+    {"__gc", gc},
+
+    {NULL}
+};
+
+
+int luaopen_triple (lua_State *L)
+{
+    luaL_newmetatable (L, "LSUP.Triple");
+    lua_pushvalue (L, -1);
+    lua_setfield (L, -2, "__index");
+    luaL_setfuncs (L, triple_lib_meth, 0);
+
+    // Enums
+    lua_pushvalue (L, TRP_POS_S);
+    lua_setfield (L, -1, "TRP_POS_S");
+    lua_pushvalue (L, TRP_POS_P);
+    lua_setfield (L, -1, "TRP_POS_P");
+    lua_pushvalue (L, TRP_POS_O);
+    lua_setfield (L, -1, "TRP_POS_O");
+
+    luaL_newlib (L, triple_lib_fn);
+
+    return 1;
+}
+