|
@@ -54,9 +54,8 @@ static int l_graph_list (lua_State *L)
|
|
|
|
|
|
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");
|
|
|
|
|
|
- return 1;
|
|
|
+ return tset_to_udata (L, ts);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -78,7 +77,7 @@ static int l_graph_gc (lua_State *L)
|
|
|
|
|
|
static int l_graph_get_uri (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
|
|
|
VOLK_Term **tp = lua_newuserdata (L, sizeof *tp);
|
|
|
luaL_getmetatable (L, "VOLK.Term");
|
|
@@ -93,7 +92,7 @@ static int l_graph_get_uri (lua_State *L)
|
|
|
|
|
|
static int l_graph_to_string (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
lua_pushfstring (
|
|
|
L, "VOLK.Graph @%p <%s>: %d triples",
|
|
|
gr, VOLK_graph_uri (gr)->data, VOLK_graph_size (gr));
|
|
@@ -104,7 +103,7 @@ static int l_graph_to_string (lua_State *L)
|
|
|
|
|
|
static int l_graph_len (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
lua_pushinteger (L, VOLK_graph_size (gr));
|
|
|
|
|
|
return 1;
|
|
@@ -113,16 +112,16 @@ static int l_graph_len (lua_State *L)
|
|
|
|
|
|
static int l_graph_copy (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *src = check_graph (L);
|
|
|
- VOLK_Graph *dest = *(VOLK_Graph **)luaL_checkudata (L, 2, "VOLK.Graph");
|
|
|
+ const VOLK_Graph *src = check_graph (L, 1);
|
|
|
+ VOLK_Graph *dest = check_graph (L, 2);
|
|
|
const VOLK_Term *s, *p, *o;
|
|
|
|
|
|
if lua_isnoneornil (L, 3) s = NULL;
|
|
|
- else s = *(VOLK_Term **)luaL_checkudata (L, 3, "VOLK.Term");
|
|
|
+ else s = check_term (L, 3);
|
|
|
if lua_isnoneornil (L, 4) p = NULL;
|
|
|
- else p = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
|
|
|
+ else p = check_term (L, 4);
|
|
|
if lua_isnoneornil (L, 5) o = NULL;
|
|
|
- else o = *(VOLK_Term **)luaL_checkudata (L, 5, "VOLK.Term");
|
|
|
+ else o = check_term (L, 5);
|
|
|
|
|
|
LUA_PCHECK (VOLK_graph_copy_contents (
|
|
|
src, dest, s, p, o), "Error copying graph.");
|
|
@@ -133,9 +132,8 @@ static int l_graph_copy (lua_State *L)
|
|
|
|
|
|
static int l_graph_equals (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr1 = check_graph (L);
|
|
|
- const VOLK_Graph *gr2 =
|
|
|
- *(VOLK_Graph **)luaL_checkudata (L, 2, "VOLK.Graph");
|
|
|
+ const VOLK_Graph *gr1 = check_graph (L, 1);
|
|
|
+ const VOLK_Graph *gr2 = check_graph (L, 2);
|
|
|
|
|
|
LOG_DEBUG ("Comparing graphs %p %p", gr1, gr2);
|
|
|
int eq_rc = VOLK_graph_equals (gr1, gr2);
|
|
@@ -147,9 +145,8 @@ static int l_graph_equals (lua_State *L)
|
|
|
|
|
|
static int l_graph_contains (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
- const VOLK_Triple *spo =
|
|
|
- *(VOLK_Triple **)luaL_checkudata (L, 2, "VOLK.Triple");
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
+ const VOLK_Triple *spo = check_triple (L, 2);
|
|
|
|
|
|
lua_pushboolean (L, VOLK_graph_contains (gr, spo));
|
|
|
|
|
@@ -160,7 +157,7 @@ static int l_graph_contains (lua_State *L)
|
|
|
/// Initialize iterative addition.
|
|
|
static int l_graph_add_init (lua_State *L)
|
|
|
{
|
|
|
- VOLK_Graph *gr = check_graph (L);
|
|
|
+ VOLK_Graph *gr = check_graph (L, 1);
|
|
|
|
|
|
VOLK_GraphIterator **it_p = lua_newuserdata (L, sizeof *it_p);
|
|
|
luaL_getmetatable (L, "VOLK.GraphIterator");
|
|
@@ -177,9 +174,9 @@ static int l_graph_add_init (lua_State *L)
|
|
|
static int l_graph_add_iter (lua_State *L)
|
|
|
{
|
|
|
VOLK_GraphIterator **it_p = luaL_checkudata (L, 1, "VOLK.GraphIterator");
|
|
|
- const VOLK_Triple **spo = luaL_checkudata (L, 2, "VOLK.Triple");
|
|
|
+ const VOLK_Triple *spo = check_triple (L, 2);
|
|
|
|
|
|
- LUA_PCHECK (VOLK_graph_add_iter (*it_p, *spo), "Error adding triple");
|
|
|
+ LUA_PCHECK (VOLK_graph_add_iter (*it_p, spo), "Error adding triple");
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -200,7 +197,7 @@ static int l_graph_add_done (lua_State *L)
|
|
|
*/
|
|
|
static int l_graph_add (lua_State *L)
|
|
|
{
|
|
|
- VOLK_Graph *gr = check_graph (L);
|
|
|
+ VOLK_Graph *gr = check_graph (L, 1);
|
|
|
int rc;
|
|
|
VOLK_rc volk_rc= VOLK_NOACTION;
|
|
|
size_t i = 0, ct = 0;
|
|
@@ -208,8 +205,7 @@ static int l_graph_add (lua_State *L)
|
|
|
|
|
|
while ((rc = lua_rawgeti (L, 2, ++i)) != LUA_TNIL) {
|
|
|
//LOG_DEBUG ("Triple type: %s", lua_typename (L, rc));
|
|
|
- const VOLK_Triple *spo =
|
|
|
- *(VOLK_Triple **)luaL_checkudata (L, -1, "VOLK.Triple");
|
|
|
+ const VOLK_Triple *spo = check_triple (L, -1);
|
|
|
LOG_DEBUG (
|
|
|
"Got triple %d: {%s %s %s}\n",
|
|
|
i, spo->s->data, spo->p->data, spo->o->data);
|
|
@@ -230,14 +226,14 @@ static int l_graph_add (lua_State *L)
|
|
|
|
|
|
static int l_graph_remove (lua_State *L)
|
|
|
{
|
|
|
- VOLK_Graph *gr = check_graph (L);
|
|
|
+ VOLK_Graph *gr = check_graph (L, 1);
|
|
|
const VOLK_Term *s, *p, *o;
|
|
|
if lua_isnoneornil (L, 2) s = NULL;
|
|
|
- else s = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
|
|
|
+ else s = check_term (L, 2);
|
|
|
if lua_isnoneornil (L, 3) p = NULL;
|
|
|
- else p = *(VOLK_Term **)luaL_checkudata (L, 3, "VOLK.Term");
|
|
|
+ else p = check_term (L, 3);
|
|
|
if lua_isnoneornil (L, 4) o = NULL;
|
|
|
- else o = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
|
|
|
+ else o = check_term (L, 4);
|
|
|
|
|
|
size_t ct;
|
|
|
VOLK_rc rc = VOLK_graph_remove (gr, s, p, o, &ct);
|
|
@@ -279,14 +275,14 @@ static int graph_iter_next (lua_State *L)
|
|
|
|
|
|
static int l_graph_lookup (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
const VOLK_Term *s, *p, *o;
|
|
|
if lua_isnoneornil (L, 2) s = NULL;
|
|
|
- else s = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
|
|
|
+ else s = check_term (L, 2);
|
|
|
if lua_isnoneornil (L, 3) p = NULL;
|
|
|
- else p = *(VOLK_Term **)luaL_checkudata (L, 3, "VOLK.Term");
|
|
|
+ else p = check_term (L, 3);
|
|
|
if lua_isnoneornil (L, 4) o = NULL;
|
|
|
- else o = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
|
|
|
+ else o = check_term (L, 4);
|
|
|
|
|
|
VOLK_GraphIterator **it_p = lua_newuserdata (L, sizeof *it_p);
|
|
|
*it_p = NULL;
|
|
@@ -306,7 +302,7 @@ static int l_graph_lookup (lua_State *L)
|
|
|
|
|
|
static int l_graph_encode (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
const char *codec_str = lua_tostring (L, 2);
|
|
|
|
|
|
VOLK_Codec codec;
|
|
@@ -344,7 +340,7 @@ static int l_graph_encode (lua_State *L)
|
|
|
|
|
|
static int l_graph_get (lua_State *L)
|
|
|
{
|
|
|
- VOLK_Term *gr_uri = check_term (L);
|
|
|
+ VOLK_Term *gr_uri = check_term (L, 1);
|
|
|
VOLK_Store *store = *(VOLK_Store **)luaL_checkudata (L, 2, "VOLK.Store");
|
|
|
|
|
|
VOLK_Graph **gp = allocate_graph (L);
|
|
@@ -390,16 +386,18 @@ static int graph_iter_gc (lua_State *L)
|
|
|
*/
|
|
|
static int l_graph_connections (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
- VOLK_Term *t = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
+ VOLK_Term *t = check_term (L, 2);
|
|
|
const VOLK_LinkType type = luaL_checkinteger (L, 3);
|
|
|
LOG_DEBUG ("Adding term for connections: @%p", *t);
|
|
|
|
|
|
+ VOLK_LinkMap *lm = VOLK_graph_connections (gr, t, type);
|
|
|
+ LUA_NLCHECK (lm, "Error creating link map.");
|
|
|
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.");
|
|
|
+ *lm_p = lm;
|
|
|
luaL_getmetatable (L, "VOLK.LinkMap");
|
|
|
lua_setmetatable (L, -2);
|
|
|
+ LUA_NLCHECK (*lm_p, "Error creating Link map.");
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
@@ -407,30 +405,28 @@ static int l_graph_connections (lua_State *L)
|
|
|
|
|
|
static int l_graph_term_set (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
- const VOLK_Term *t1 = *(VOLK_Term **)luaL_checkudata (L, 2, "VOLK.Term");
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
+ const VOLK_Term *t1 = check_term (L, 2);
|
|
|
const VOLK_TriplePos t1_pos = luaL_checkinteger (L, 3);
|
|
|
- const VOLK_Term *t2 = *(VOLK_Term **)luaL_checkudata (L, 4, "VOLK.Term");
|
|
|
+ const VOLK_Term *t2 = check_term (L, 4);
|
|
|
const VOLK_TriplePos t2_pos = luaL_checkinteger (L, 5);
|
|
|
|
|
|
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");
|
|
|
|
|
|
- return 1;
|
|
|
+ return tset_to_udata (L, ts);
|
|
|
}
|
|
|
|
|
|
|
|
|
static int l_graph_unique_terms (lua_State *L)
|
|
|
{
|
|
|
- const VOLK_Graph *gr = check_graph (L);
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
const VOLK_TriplePos pos = luaL_checkinteger (L, 2);
|
|
|
|
|
|
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");
|
|
|
|
|
|
- return 1;
|
|
|
+ return tset_to_udata (L, ts);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -449,33 +445,14 @@ static int l_graph_unique_terms (lua_State *L)
|
|
|
*/
|
|
|
static int l_graph_attr (lua_State *L)
|
|
|
{
|
|
|
- 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");
|
|
|
+ const VOLK_Graph *gr = check_graph (L, 1);
|
|
|
+ const VOLK_Term *s = check_term (L, 2);
|
|
|
+ const VOLK_Term *p = check_term (L, 3);
|
|
|
|
|
|
- size_t ct;
|
|
|
- VOLK_GraphIterator *it = VOLK_graph_lookup (gr, s, p, NULL, &ct);
|
|
|
+ VOLK_TermSet *ts = VOLK_graph_term_set (gr, s, TRP_POS_S, p, TRP_POS_P);
|
|
|
+ LUA_NLCHECK (ts, "Error creating term set from attribute lookup.");
|
|
|
|
|
|
- lua_createtable (L, ct, 0);
|
|
|
- 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 = VOLK_term_copy (spo->o);
|
|
|
-
|
|
|
- lua_rawset (L, -3);
|
|
|
- }
|
|
|
- VOLK_graph_iter_free (it);
|
|
|
-
|
|
|
- if (rc != VOLK_END) LUA_PCHECK (rc, "Error iterating attr values");
|
|
|
-
|
|
|
- return 1;
|
|
|
+ return tset_to_udata (L, ts);
|
|
|
}
|
|
|
|
|
|
/*
|