Implement user's config as init file and add directory into package.path
Create the user's config init file if lite user's config directory does not exists. No longer use the awkward package.searchers but instead add user's config dir at the end of package path.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "api.h"
|
||||
#include "rencache.h"
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
@@ -314,6 +315,25 @@ static int f_get_file_info(lua_State *L) {
|
||||
}
|
||||
|
||||
|
||||
static int f_mkdir(lua_State *L) {
|
||||
const char *path = luaL_checkstring(L, 1);
|
||||
|
||||
#ifdef _WIN32
|
||||
int err = _mkdir(path);
|
||||
#else
|
||||
int err = mkdir(path, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
|
||||
#endif
|
||||
if (err < 0) {
|
||||
lua_pushboolean(L, 0);
|
||||
lua_pushstring(L, strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
|
||||
lua_pushboolean(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int f_get_clipboard(lua_State *L) {
|
||||
char *text = SDL_GetClipboardText();
|
||||
if (!text) { return 0; }
|
||||
@@ -397,6 +417,7 @@ static const luaL_Reg lib[] = {
|
||||
{ "window_has_focus", f_window_has_focus },
|
||||
{ "show_confirm_dialog", f_show_confirm_dialog },
|
||||
{ "chdir", f_chdir },
|
||||
{ "mkdir", f_mkdir },
|
||||
{ "list_dir", f_list_dir },
|
||||
{ "absolute_path", f_absolute_path },
|
||||
{ "get_file_info", f_get_file_info },
|
||||
|
||||
+3
-24
@@ -125,34 +125,13 @@ int main(int argc, char **argv) {
|
||||
" EXEDIR = EXEFILE:match(\"^(.+)[/\\\\].*$\")\n"
|
||||
#ifdef LITE_XL_DATA_USE_EXEDIR
|
||||
" DATADIR = EXEDIR .. '/data'\n"
|
||||
" USERDIR = EXEDIR .. '/user'\n"
|
||||
#else
|
||||
" local prefix = EXEDIR:match(\"^(.+)[/\\\\]bin$\")\n"
|
||||
" DATADIR = prefix and (prefix .. '/share/lite-xl') or (EXEDIR .. '/data')\n"
|
||||
" USERDIR = os.getenv(\"HOME\") .. '/.config/lite-xl'\n"
|
||||
|
||||
"table.insert(package.searchers, 1, function(module_name)\n"
|
||||
" if module_name == 'user' or module_name:match('^user%.') then\n"
|
||||
" return function(x_module_name)\n"
|
||||
" local filename, err\n"
|
||||
" if x_module_name == 'user' then\n"
|
||||
" filename = USERDIR..'/init.lua'\n"
|
||||
" else\n"
|
||||
" local modname = x_module_name:gsub('^user%.', '')\n"
|
||||
" filename, err = package.searchpath(modname, USERDIR..'/?.lua;'..USERDIR..'/?/init.lua')\n"
|
||||
" end\n"
|
||||
" if filename then\n"
|
||||
" local module_f, module_err = loadfile(filename)\n"
|
||||
" if module_f then\n"
|
||||
" return module_f()\n"
|
||||
" else\n"
|
||||
" return nil, module_err\n"
|
||||
" end\n"
|
||||
" else\n"
|
||||
" return nil, err\n"
|
||||
" end\n"
|
||||
" end\n"
|
||||
" end\n"
|
||||
"end)\n"
|
||||
" package.path = package.path .. ';' .. DATADIR .. '/?.lua'\n"
|
||||
" package.path = package.path .. ';' .. DATADIR .. '/?/init.lua'\n"
|
||||
#endif
|
||||
" package.path = DATADIR .. '/?.lua;' .. package.path\n"
|
||||
" package.path = DATADIR .. '/?/init.lua;' .. package.path\n"
|
||||
|
||||
Reference in New Issue
Block a user