#include //#include #include #include #define check_nsm(L) \ *(LSUP_NSMap **)luaL_checkudata(L, 1, "LSUP.NSMap") lua_State *L; /* * Factory methods. */ static int l_nsm_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) luaL_error (L, "Error while creating a term!"); return 1; } /* * Class methods. */ static int l_nsm_gc (lua_State *L) { LSUP_NSMap *nsm = check_nsm (L); if (nsm) LSUP_nsmap_free (nsm); return 0; } /* * Library setup. */ static const struct luaL_Reg nsm_lib_fn [] = { {"nsm_new", l_nsm_new}, {NULL} }; static const struct luaL_Reg nsm_lib_meth [] = { {"__gc", l_nsm_gc}, {NULL} }; int luaopen_namespace (lua_State *L) { luaL_newmetatable (L, "LSUP.NSMap"); lua_pushvalue (L, -1); lua_setfield (L, -2, "__index"); luaL_setfuncs (L, nsm_lib_meth, 0); luaL_newlib (L, nsm_lib_fn); return 1; }