|
@@ -1,49 +1,18 @@
|
|
|
#include "lua_lsup.h"
|
|
|
|
|
|
-#define check_nsm(L) \
|
|
|
- *(LSUP_NSMap **)luaL_checkudata(L, 1, "LSUP.NSMap")
|
|
|
-
|
|
|
-
|
|
|
-/*
|
|
|
- * Factory methods.
|
|
|
- */
|
|
|
-
|
|
|
-int l_nsmap_new (lua_State *L)
|
|
|
-{
|
|
|
- LSUP_NSMap **nsm_p = lua_newuserdatauv (L, sizeof (*nsm_p), 1);
|
|
|
- luaL_getmetatable (L, "LSUP.NSMap");
|
|
|
- lua_setmetatable (L, -2);
|
|
|
-
|
|
|
- *nsm_p = LSUP_nsmap_new ();
|
|
|
- if (!*nsm_p) return luaL_error (L, "Error while creating namespace map.");
|
|
|
-
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
/*
|
|
|
* Class methods.
|
|
|
*/
|
|
|
|
|
|
-static int l_nsmap_gc (lua_State *L)
|
|
|
-{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
- LOG_DEBUG ("Garbage collecting NSM @%p", nsm);
|
|
|
- if (nsm) LSUP_nsmap_free (nsm);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
static int l_nsmap_add (lua_State *L)
|
|
|
{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
const char
|
|
|
- *pfx = luaL_checkstring (L, 2),
|
|
|
- *nsstr = luaL_checkstring (L, 3);
|
|
|
+ *pfx = luaL_checkstring (L, 1),
|
|
|
+ *nsstr = luaL_checkstring (L, 2);
|
|
|
|
|
|
LUA_PCHECK (
|
|
|
- LSUP_nsmap_add (nsm, pfx, nsstr),
|
|
|
+ LSUP_nsmap_add (pfx, nsstr),
|
|
|
"Error adding member to NS map");
|
|
|
|
|
|
return 0;
|
|
@@ -52,11 +21,10 @@ static int l_nsmap_add (lua_State *L)
|
|
|
|
|
|
static int l_nsmap_remove (lua_State *L)
|
|
|
{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
- const char *pfx = luaL_checkstring (L, 2);
|
|
|
+ const char *pfx = luaL_checkstring (L, 1);
|
|
|
|
|
|
LUA_PCHECK (
|
|
|
- LSUP_nsmap_remove (nsm, pfx),
|
|
|
+ LSUP_nsmap_remove (pfx),
|
|
|
"Error removing member to NS map");
|
|
|
|
|
|
return 0;
|
|
@@ -65,10 +33,9 @@ static int l_nsmap_remove (lua_State *L)
|
|
|
|
|
|
static int l_nsmap_get_ns (lua_State *L)
|
|
|
{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
- const char *pfx = luaL_checkstring (L, 2);
|
|
|
+ const char *pfx = luaL_checkstring (L, 1);
|
|
|
|
|
|
- const char *ns = LSUP_nsmap_get_ns (nsm, pfx);
|
|
|
+ const char *ns = LSUP_nsmap_get_ns (pfx);
|
|
|
|
|
|
if (ns) lua_pushstring (L, ns);
|
|
|
else return 0;
|
|
@@ -79,10 +46,9 @@ static int l_nsmap_get_ns (lua_State *L)
|
|
|
|
|
|
static int l_nsmap_get_pfx (lua_State *L)
|
|
|
{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
- const char *ns = luaL_checkstring (L, 2);
|
|
|
+ const char *ns = luaL_checkstring (L, 1);
|
|
|
|
|
|
- const char *pfx = LSUP_nsmap_get_pfx (nsm, ns);
|
|
|
+ const char *pfx = LSUP_nsmap_get_pfx (ns);
|
|
|
|
|
|
if (pfx) lua_pushstring (L, pfx);
|
|
|
else lua_pushnil (L);
|
|
@@ -93,12 +59,11 @@ static int l_nsmap_get_pfx (lua_State *L)
|
|
|
|
|
|
static int l_nsmap_normalize_uri (lua_State *L)
|
|
|
{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
- const char *pfx_uri = luaL_checkstring (L, 2);
|
|
|
+ const char *pfx_uri = luaL_checkstring (L, 1);
|
|
|
|
|
|
char *fq_uri;
|
|
|
LUA_PCHECK (
|
|
|
- LSUP_nsmap_normalize_uri (nsm, pfx_uri, &fq_uri),
|
|
|
+ LSUP_nsmap_normalize_uri (pfx_uri, &fq_uri),
|
|
|
"Error normalizing URI");
|
|
|
|
|
|
if (fq_uri) lua_pushstring (L, fq_uri);
|
|
@@ -111,12 +76,11 @@ static int l_nsmap_normalize_uri (lua_State *L)
|
|
|
|
|
|
static int l_nsmap_denormalize_uri (lua_State *L)
|
|
|
{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
- const char *fq_uri = luaL_checkstring (L, 2);
|
|
|
+ const char *fq_uri = luaL_checkstring (L, 1);
|
|
|
|
|
|
char *pfx_uri;
|
|
|
LUA_PCHECK (
|
|
|
- LSUP_nsmap_denormalize_uri (nsm, fq_uri, &pfx_uri),
|
|
|
+ LSUP_nsmap_denormalize_uri (fq_uri, &pfx_uri),
|
|
|
"Error denormalizing URI");
|
|
|
|
|
|
if (pfx_uri) lua_pushstring (L, pfx_uri);
|
|
@@ -127,14 +91,6 @@ static int l_nsmap_denormalize_uri (lua_State *L)
|
|
|
}
|
|
|
|
|
|
|
|
|
-/*
|
|
|
-static int l_nsmap_iter_next (lua_State *L)
|
|
|
-{
|
|
|
- // TODO
|
|
|
- return 0;
|
|
|
-}
|
|
|
-*/
|
|
|
-
|
|
|
static int nsmap_iter_next (lua_State *L)
|
|
|
{
|
|
|
const char ****data_p = lua_touserdata (L, lua_upvalueindex (1));
|
|
@@ -159,11 +115,10 @@ static int nsmap_iter_next (lua_State *L)
|
|
|
|
|
|
static int l_nsmap_iter (lua_State *L)
|
|
|
{
|
|
|
- LSUP_NSMap *nsm = check_nsm (L);
|
|
|
const char ****data_p = lua_newuserdata (L, sizeof (*data_p));
|
|
|
//luaL_getmetatable (L, "LSUP.String2DIterator");
|
|
|
//lua_setmetatable (L, -2);
|
|
|
- *data_p = LSUP_nsmap_dump (nsm);
|
|
|
+ *data_p = LSUP_nsmap_dump ();
|
|
|
LUA_NLCHECK (*data_p, "Error creating NS map iterator.");
|
|
|
|
|
|
size_t *i = malloc (sizeof (*i));
|
|
@@ -182,33 +137,31 @@ static int l_nsmap_iter (lua_State *L)
|
|
|
*/
|
|
|
|
|
|
static const luaL_Reg nsmap_lib_fn [] = {
|
|
|
- {"new", l_nsmap_new},
|
|
|
- {NULL}
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-static const luaL_Reg nsmap_lib_meth [] = {
|
|
|
- {"__gc", l_nsmap_gc},
|
|
|
- {"__pairs", l_nsmap_iter},
|
|
|
-
|
|
|
{"add", l_nsmap_add},
|
|
|
{"remove", l_nsmap_remove},
|
|
|
{"get_ns", l_nsmap_get_ns},
|
|
|
{"get_pfx", l_nsmap_get_pfx},
|
|
|
{"normalize_uri", l_nsmap_normalize_uri},
|
|
|
{"denormalize_uri", l_nsmap_denormalize_uri},
|
|
|
- //{"iter", l_nsmap_iter},
|
|
|
+ {"iter", l_nsmap_iter},
|
|
|
|
|
|
{NULL}
|
|
|
};
|
|
|
|
|
|
|
|
|
+/*
|
|
|
+static const luaL_Reg nsmap_lib_meth [] = {
|
|
|
+ {NULL}
|
|
|
+};
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
int luaopen_lsup_namespace (lua_State *L)
|
|
|
{
|
|
|
luaL_newmetatable (L, "LSUP.NSMap");
|
|
|
lua_pushvalue (L, -1);
|
|
|
- lua_setfield (L, -2, "__index");
|
|
|
- luaL_setfuncs (L, nsmap_lib_meth, 0);
|
|
|
+ //lua_setfield (L, -2, "__index");
|
|
|
+ //luaL_setfuncs (L, nsmap_lib_meth, 0);
|
|
|
luaL_newlib (L, nsmap_lib_fn);
|
|
|
|
|
|
//luaL_newmetatable (L, "LSUP.String2DIterator");
|