stylish updates.
[apps/madmutt.git] / lib-lua / runtime.c
index becd6de..0fb777c 100644 (file)
  */
 
 #include <lib-lib/lib-lib.h>
-
-#include <lua.h>
-#include <lualib.h>
-#include <lauxlib.h>
-
-#include "lib-lua.h"
+#include "lib-lua_priv.h"
 
 static lua_State *L;
+static reg_entry registry[LTK_count];
 
 static const luaL_Reg lualibs[] = {
     {"",              luaopen_base},
+    {LUA_OSLIBNAME,   luaopen_os},
     {LUA_LOADLIBNAME, luaopen_package},
     {LUA_TABLIBNAME,  luaopen_table},
     {LUA_IOLIBNAME,   luaopen_io},
     {LUA_STRLIBNAME,  luaopen_string},
     {LUA_MATHLIBNAME, luaopen_math},
     {LUA_DBLIBNAME,   luaopen_debug},
-};
-
-static const struct luaL_Reg madmutt_module_funcs[] = {
-    {NULL, NULL}
-};
-
-static const struct {
-    const char *key;
-    const char *value;
-} madmutt_module_vars[] = {
-    { "version",    VERSION },
-    /*
-     ** .pp
-     ** \fIThis is a read-only system property and specifies madmutt's
-     ** version string.\fP
-     */
-    { "sysconfdir", SYSCONFDIR },
-    /*
-     ** .pp
-     ** \fIThis is a read-only system property and specifies madmutt's
-     ** subversion revision string.\fP
-     */
-    { "bindir",     BINDIR },
-    /*
-     ** .pp
-     ** \fIThis is a read-only system property and specifies the
-     ** directory containing the madmutt binary.\fP
-     */
-    { "docdir",     PKGDOCDIR },
-    /*
-     ** .pp
-     ** \fIThis is a read-only system property and specifies the
-     ** directory containing the madmutt documentation.\fP
-     */
-#ifdef USE_HCACHE
-#if defined(HAVE_QDBM)
-    {"hcache_backend", "qdbm" },
-#elif defined(HAVE_GDBM)
-    {"hcache_backend", "gdbm" },
-#elif defined(HAVE_DB4)
-    {"hcache_backend", "db4" },
-#else
-    {"hcache_backend", "unknown" },
-#endif
-    /*
-     ** .pp
-     ** \fIThis is a read-only system property and specifies the
-     ** header chaching's database backend.\fP
-     */
-#endif
+    {LUA_MADMUTT,     luaopen_madmutt},
 };
 
 void mlua_initialize(void)
@@ -97,12 +45,6 @@ void mlua_initialize(void)
         lua_pushstring(L, lualibs[i].name);
         lua_call(L, 1, 0);
     }
-    luaL_register(L, "madmutt", madmutt_module_funcs);
-
-    for (i = 0; i < countof(madmutt_module_vars); i++) {
-        lua_pushstring(L, madmutt_module_vars[i].value);
-        lua_setfield(L, -2, madmutt_module_vars[i].key);
-    }
 }
 
 void mlua_shutdown(void)
@@ -125,3 +67,30 @@ int mlua_wrap(void (*errfun)(const char *fmt, ...), int status)
     return status;
 }
 
+const char *mlua_reggets(int tk)
+{
+    if (registry[tk].type != REG_STR)
+        return NULL;
+    return registry[tk].s;
+}
+
+int mlua_reggeti(int tk)
+{
+    if (registry[tk].type != REG_INT)
+        return -1;
+    return registry[tk].i;
+}
+
+void mlua_regsets(int tk, const char *s)
+{
+    reg_entry_wipe(registry + tk);
+    registry[tk].type = REG_STR;
+    registry[tk].s    = m_strdup(s);
+}
+
+void mlua_regseti(int tk, int i)
+{
+    reg_entry_wipe(registry + tk);
+    registry[tk].type = REG_INT;
+    registry[tk].i    = i;
+}