summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bin/elua/main.c87
-rw-r--r--src/lib/elua/Elua.h1
-rw-r--r--src/lib/elua/elua.c38
3 files changed, 75 insertions, 51 deletions
diff --git a/src/bin/elua/main.c b/src/bin/elua/main.c
index 38cf5cea67..ed83b7027b 100644
--- a/src/bin/elua/main.c
+++ b/src/bin/elua/main.c
@@ -288,8 +288,7 @@ elua_main(lua_State *L)
288 hasexec = EINA_FALSE; 288 hasexec = EINA_FALSE;
289 Eina_List *largs = NULL, *l = NULL; 289 Eina_List *largs = NULL, *l = NULL;
290 Arg_Data *data = NULL; 290 Arg_Data *data = NULL;
291 char *coredir = NULL, *moddir = NULL, *appsdir = NULL; 291 const char *coredir = NULL, *moddir = NULL, *appsdir = NULL;
292 char coredirbuf[PATH_MAX], moddirbuf[PATH_MAX], appsdirbuf[PATH_MAX];
293 char modfile[PATH_MAX]; 292 char modfile[PATH_MAX];
294 293
295 int ch; 294 int ch;
@@ -306,29 +305,31 @@ elua_main(lua_State *L)
306 { 305 {
307 switch (ch) 306 switch (ch)
308 { 307 {
309 case 'h': 308 case 'h':
310 elua_print_help(elua_progname, stdout); 309 elua_print_help(elua_progname, stdout);
311 return 0; 310 return 0;
312 case 'C': 311 case 'C':
313 coredir = optarg; 312 coredir = optarg;
313 break;
314 case 'M':
315 moddir = optarg;
316 break;
317 case 'A':
318 appsdir = optarg;
319 break;
320 case 'e':
321 case 'l':
322 case 'I':
323 {
324 Arg_Data *v = malloc(sizeof(Arg_Data));
325 v->type = (ch == 'e') ? ARG_CODE : ((ch == 'l')
326 ? ARG_LIBRARY : ARG_LIBDIR);
327 v->value = optarg;
328 largs = eina_list_append(largs, v);
314 break; 329 break;
315 case 'M': 330 }
316 moddir = optarg; 331 case 'E':
317 break; 332 noenv = EINA_TRUE;
318 case 'A':
319 appsdir = optarg;
320 break;
321 case 'e':
322 case 'l':
323 case 'I':
324 {
325 Arg_Data *v = malloc(sizeof(Arg_Data));
326 v->type = (ch == 'e') ? ARG_CODE : ((ch == 'l')
327 ? ARG_LIBRARY : ARG_LIBDIR);
328 v->value = optarg;
329 largs = eina_list_append(largs, v);
330 break;
331 }
332 } 333 }
333 } 334 }
334 335
@@ -347,36 +348,20 @@ elua_main(lua_State *L)
347 return 0; 348 return 0;
348 } 349 }
349 350
350 if (!coredir) 351 elua_state_dirs_set(es, coredir, moddir, appsdir);
351 { 352 elua_state_dirs_fill(es, noenv);
352 if (noenv || !(coredir = getenv("ELUA_CORE_DIR")) || !coredir[0]) 353
353 { 354 coredir = elua_state_core_dir_get(es);
354 coredir = coredirbuf; 355 moddir = elua_state_mod_dir_get(es);
355 snprintf(coredirbuf, sizeof(coredirbuf), "%s/core", 356 appsdir = elua_state_apps_dir_get(es);
356 eina_prefix_data_get(elua_prefix)); 357
357 } 358 if (!coredir || !moddir || !appsdir)
358 }
359 if (!moddir)
360 {
361 if (noenv || !(moddir = getenv("ELUA_MODULES_DIR")) || !moddir[0])
362 {
363 moddir = moddirbuf;
364 snprintf(moddirbuf, sizeof(moddirbuf), "%s/modules",
365 eina_prefix_data_get(elua_prefix));
366 }
367 }
368 if (!appsdir)
369 { 359 {
370 if (noenv || !(appsdir = getenv("ELUA_APPS_DIR")) || !appsdir[0]) 360 ERR("could not set one or more script directories");
371 { 361 m->status = 1;
372 appsdir = appsdirbuf; 362 return 0;
373 snprintf(appsdirbuf, sizeof(appsdirbuf), "%s/apps",
374 eina_prefix_data_get(elua_prefix));
375 }
376 } 363 }
377 364
378 elua_state_dirs_set(es, coredir, moddir, appsdir);
379
380 snprintf(modfile, sizeof(modfile), "%s/module.lua", coredir); 365 snprintf(modfile, sizeof(modfile), "%s/module.lua", coredir);
381 if (elua_report_error(es, elua_progname, elua_io_loadfile(es, modfile))) 366 if (elua_report_error(es, elua_progname, elua_io_loadfile(es, modfile)))
382 { 367 {
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index b72ada52c7..a05b82433c 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -72,6 +72,7 @@ EAPI void elua_state_free(Elua_State *es);
72 72
73EAPI void elua_state_dirs_set(Elua_State *es, const char *core, 73EAPI void elua_state_dirs_set(Elua_State *es, const char *core,
74 const char *mods, const char *apps); 74 const char *mods, const char *apps);
75EAPI void elua_state_dirs_fill(Elua_State *es, Eina_Bool ignore_env);
75 76
76EAPI Eina_Stringshare *elua_state_core_dir_get(const Elua_State *es); 77EAPI Eina_Stringshare *elua_state_core_dir_get(const Elua_State *es);
77EAPI Eina_Stringshare *elua_state_mod_dir_get(const Elua_State *es); 78EAPI Eina_Stringshare *elua_state_mod_dir_get(const Elua_State *es);
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index 3ab2448427..ae5da0e012 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -109,6 +109,44 @@ elua_state_dirs_set(Elua_State *es, const char *core, const char *mods,
109 if (apps) es->appsdir = eina_stringshare_add(apps); 109 if (apps) es->appsdir = eina_stringshare_add(apps);
110} 110}
111 111
112EAPI void
113elua_state_dirs_fill(Elua_State *es, Eina_Bool ignore_env)
114{
115 const char *coredir = NULL, *moddir = NULL, *appsdir = NULL;
116 char coredirbuf[PATH_MAX], moddirbuf[PATH_MAX], appsdirbuf[PATH_MAX];
117 EINA_SAFETY_ON_NULL_RETURN(es);
118 if (!(coredir = es->coredir))
119 {
120 if (ignore_env || !(coredir = getenv("ELUA_CORE_DIR")) || !coredir[0])
121 {
122 coredir = coredirbuf;
123 snprintf(coredirbuf, sizeof(coredirbuf), "%s/core",
124 eina_prefix_data_get(_elua_pfx));
125 }
126 if (coredir) es->coredir = eina_stringshare_add(coredir);
127 }
128 if (!(moddir = es->moddir))
129 {
130 if (ignore_env || !(moddir = getenv("ELUA_MODULES_DIR")) || !moddir[0])
131 {
132 moddir = moddirbuf;
133 snprintf(moddirbuf, sizeof(moddirbuf), "%s/modules",
134 eina_prefix_data_get(_elua_pfx));
135 }
136 if (moddir) es->moddir = eina_stringshare_add(moddir);
137 }
138 if (!(appsdir = es->appsdir))
139 {
140 if (ignore_env || !(appsdir = getenv("ELUA_APPS_DIR")) || !appsdir[0])
141 {
142 appsdir = appsdirbuf;
143 snprintf(appsdirbuf, sizeof(appsdirbuf), "%s/apps",
144 eina_prefix_data_get(_elua_pfx));
145 }
146 if (appsdir) es->appsdir = eina_stringshare_add(appsdir);
147 }
148}
149
112EAPI Eina_Stringshare * 150EAPI Eina_Stringshare *
113elua_state_core_dir_get(const Elua_State *es) 151elua_state_core_dir_get(const Elua_State *es)
114{ 152{