X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-lua%2Fruntime.c;h=e4482f2c1c86bf67a6aad0dc8a61c70f3affbb7d;hb=b1c9f537b475b3bc8f6517bb4d7008a411bb478e;hp=f36af4d41055a1d40be3593d12a641929ce2302b;hpb=6141042cd0f8e305182da8dd77d21b40d5aa8b4f;p=apps%2Fmadmutt.git diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index f36af4d..e4482f2 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -18,78 +18,25 @@ */ #include - -#include -#include -#include - -#include "lib-lua.h" +#include "lib-lua_priv.h" static lua_State *L; -static const luaL_Reg lualibs[] = { - {"", luaopen_base}, - {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 - { NULL, NULL } -}; -void mlua_initialize(void) +void luaM_initialize(void) { + 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}, + {"madmutt", luaopen_madmutt}, + }; + int i; L = lua_open(); @@ -98,30 +45,20 @@ 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++) { - char buffer[STRING]; - - snprintf(buffer, sizeof(buffer), "madmutt.%s = \"%s\";", - madmutt_module_vars[i].key, - madmutt_module_vars[i].value); - (void)luaL_dostring(L, buffer); - } } -void mlua_shutdown(void) +void luaM_shutdown(void) { lua_close(L); } -int mlua_dofile(const char *filename) +int luaM_dofile(const char *filename) { return luaL_dofile(L, filename); } -int mlua_wrap(void (*errfun)(const char *fmt, ...), int status) +int luaM_wrap(void (*errfun)(const char *fmt, ...), int status) { if (status) { (*errfun)("-[lua]-: %s\n", lua_tostring(L, -1)); @@ -130,3 +67,16 @@ int mlua_wrap(void (*errfun)(const char *fmt, ...), int status) return status; } + +quadopt_t luaM_checkquadopt(lua_State *Ls, int narg) +{ + const char *s; + int i = luaL_checkinteger(Ls, narg); + + if (i & ~3) { + s = lua_pushfstring(Ls, "int in [0-3] expected, got %d", i); + return luaL_argerror(Ls, narg, s); + } + return i; +} +