diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a7284e10a9cdf462f678ee3a3601b3c4697987d..7d6bc5d0dd29a3a643caa684bfe6b7dac805bd96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,26 @@ if (NOT DEFINED CMAKE_MAN_DIR) set (CMAKE_MAN_DIR "man") endif() +# +# Specify system-specific Lua prefixes +# +if (NOT DEFINED LUA_SYSPATH) + set (LUA_SYSPATH "") +endif() +if (NOT DEFINED LUA_SYSCPATH) + set (LUA_SYSCPATH "") +endif() + +# +# Specify Tarantool modules Lua prefixes +# +if (NOT DEFINED LUA_LIBPATH) + set (LUA_LIBPATH "") +endif() +if (NOT DEFINED LUA_LIBCPATH) + set (LUA_LIBCPATH "") +endif() + # # Now handle all configuration options. # diff --git a/include/config.h.cmake b/include/config.h.cmake index d253758e2ee2bb3a79649f00df2d2b8ac7ab00e4..22a8e529117fcead0658936f90077f2f6d3c2d04 100644 --- a/include/config.h.cmake +++ b/include/config.h.cmake @@ -111,6 +111,10 @@ #define TARANTOOL_CXX_FLAGS "@TARANTOOL_CXX_FLAGS@" #define TARANTOOL_OBJC_FLAGS "@TARANTOOL_OBJC_FLAGS@" #define TARANTOOL_OBJCXX_FLAGS "@TARANTOOL_OBJCXX_FLAGS@" +#define LUA_SYSPATH "@LUA_SYSPATH@" +#define LUA_SYSCPATH "@LUA_SYSCPATH@" +#define LUA_LIBPATH "@LUA_LIBPATH@" +#define LUA_LIBCPATH "@LUA_LIBCPATH@" /* * vim: syntax=c */ diff --git a/src/lua/init.m b/src/lua/init.m index 0f39799f8cc1581e2e2f9eadf1dc5d960d3fc064..d1fad06dcc1ce38afcf87ce8c53f2d09c351386c 100644 --- a/src/lua/init.m +++ b/src/lua/init.m @@ -1083,6 +1083,32 @@ tarantool_lua_error_init(struct lua_State *L) { lua_pop(L, 1); } +static void +tarantool_lua_setpath(struct lua_State *L, const char *type, ...) +__attribute__((sentinel)); + +static void +tarantool_lua_setpath(struct lua_State *L, const char *type, ...) +{ + char path[1024]; + va_list args; + va_start(args, type); + int off = 0; + const char *p; + while ((p = va_arg(args, const char*))) + if (*p != '\0') + off += snprintf(path + off, sizeof(path) - off, "%s;", p); + va_end(args); + lua_getglobal(L, "package"); + lua_getfield(L, -1, type); + snprintf(path + off, sizeof(path) - off, "%s", + lua_tostring(L, -1)); + lua_pop(L, 1); + lua_pushstring(L, path); + lua_setfield(L, -2, type); + lua_pop(L, 1); +} + struct lua_State * tarantool_lua_init() { @@ -1090,6 +1116,12 @@ tarantool_lua_init() if (L == NULL) return L; luaL_openlibs(L); + + tarantool_lua_setpath(L, "path", cfg.script_dir, LUA_LIBPATH, + LUA_SYSPATH, NULL); + tarantool_lua_setpath(L, "cpath", LUA_LIBCPATH, + LUA_SYSCPATH, NULL); + /* Loading 'ffi' extension and making it inaccessible */ lua_getglobal(L, "require"); lua_pushstring(L, "ffi"); @@ -1290,7 +1322,6 @@ load_init_script(va_list ap) snprintf(path, PATH_MAX, "%s/%s", cfg.script_dir, TARANTOOL_LUA_INIT_SCRIPT); - if (access(path, F_OK) == 0) { say_info("loading %s", path); /* Execute the init file. */