summaryrefslogtreecommitdiff
path: root/src/bin/elua
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-04-08 14:43:52 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:18 +0100
commitc1487c8b11ebcca01c28111ac5dcf742e0e61276 (patch)
tree6df2ffd54ea636b6759764163eb4fe96bca40b75 /src/bin/elua
parent357d902b87d0b0e74f3db400f77db985f8add19f (diff)
elua: elua_report_error now takes Elua_State*
Diffstat (limited to 'src/bin/elua')
-rw-r--r--src/bin/elua/main.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/bin/elua/main.c b/src/bin/elua/main.c
index 7b63461522..43d62c6936 100644
--- a/src/bin/elua/main.c
+++ b/src/bin/elua/main.c
@@ -70,9 +70,10 @@ elua_traceback(lua_State *L)
70} 70}
71 71
72static int 72static int
73elua_docall(lua_State *L, int narg, int nret) 73elua_docall(Elua_State *es, int narg, int nret)
74{ 74{
75 int status; 75 int status;
76 lua_State *L = es->luastate;
76 int bs = lua_gettop(L) - narg; 77 int bs = lua_gettop(L) - narg;
77 lua_pushcfunction(L, elua_traceback); 78 lua_pushcfunction(L, elua_traceback);
78 lua_insert(L, bs); 79 lua_insert(L, bs);
@@ -188,25 +189,29 @@ elua_register_require(lua_State *L)
188} 189}
189 190
190static int 191static int
191elua_dolib(lua_State *L, const char *libname) 192elua_dolib(Elua_State *es, const char *libname)
192{ 193{
194 lua_State *L = es->luastate;
193 lua_rawgeti(L, LUA_REGISTRYINDEX, elua_require_ref); 195 lua_rawgeti(L, LUA_REGISTRYINDEX, elua_require_ref);
194 lua_pushstring(L, libname); 196 lua_pushstring(L, libname);
195 return elua_report_error(L, elua_progname, lua_pcall(L, 1, 0, 0)); 197 return elua_report_error(es, elua_progname, lua_pcall(L, 1, 0, 0));
196} 198}
197 199
198static int 200static int
199elua_dofile(lua_State *L, const char *fname) 201elua_dofile(Elua_State *es, const char *fname)
200{ 202{
201 return elua_report_error(L, elua_progname, elua_io_loadfile(L, fname) 203 return elua_report_error(es, elua_progname,
202 || elua_docall(L, 0, 1)); 204 elua_io_loadfile(es->luastate, fname)
205 || elua_docall(es, 0, 1));
203} 206}
204 207
205static int 208static int
206elua_dostr(lua_State *L, const char *chunk, const char *chname) 209elua_dostr(Elua_State *es, const char *chunk, const char *chname)
207{ 210{
208 return elua_report_error(L, elua_progname, luaL_loadbuffer(L, chunk, 211 return elua_report_error(es, elua_progname,
209 strlen(chunk), chname) || elua_docall(L, 0, 0)); 212 luaL_loadbuffer(es->luastate, chunk, strlen(chunk),
213 chname)
214 || elua_docall(es, 0, 0));
210} 215}
211 216
212static Eina_Bool 217static Eina_Bool
@@ -225,9 +230,10 @@ elua_loadapp(lua_State *L, const char *appname)
225} 230}
226 231
227static int 232static int
228elua_doscript(lua_State *L, int argc, char **argv, int n, int *quit) 233elua_doscript(Elua_State *es, int argc, char **argv, int n, int *quit)
229{ 234{
230 int status; 235 int status;
236 lua_State *L = es->luastate;
231 const char *fname = argv[n]; 237 const char *fname = argv[n];
232 int narg = elua_getargs(L, argc, argv, n); 238 int narg = elua_getargs(L, argc, argv, n);
233 lua_setglobal(L, "arg"); 239 lua_setglobal(L, "arg");
@@ -254,7 +260,7 @@ elua_doscript(lua_State *L, int argc, char **argv, int n, int *quit)
254 lua_insert(L, -(narg + 1)); 260 lua_insert(L, -(narg + 1));
255 if (!status) 261 if (!status)
256 { 262 {
257 status = elua_docall(L, narg, 1); 263 status = elua_docall(es, narg, 1);
258 } 264 }
259 else 265 else
260 { 266 {
@@ -265,7 +271,7 @@ elua_doscript(lua_State *L, int argc, char **argv, int n, int *quit)
265 *quit = lua_toboolean(L, -1); 271 *quit = lua_toboolean(L, -1);
266 lua_pop(L, 1); 272 lua_pop(L, 1);
267 } 273 }
268 return elua_report_error(L, elua_progname, status); 274 return elua_report_error(es, elua_progname, status);
269} 275}
270 276
271void 277void
@@ -448,7 +454,7 @@ elua_main(lua_State *L)
448 } 454 }
449 } 455 }
450 snprintf(modfile, sizeof(modfile), "%s/module.lua", coref); 456 snprintf(modfile, sizeof(modfile), "%s/module.lua", coref);
451 if (elua_report_error(L, elua_progname, elua_io_loadfile(L, modfile))) 457 if (elua_report_error(elua_state, elua_progname, elua_io_loadfile(L, modfile)))
452 { 458 {
453 m->status = 1; 459 m->status = 1;
454 return 0; 460 return 0;
@@ -464,7 +470,7 @@ elua_main(lua_State *L)
464 lua_call(L, 2, 0); 470 lua_call(L, 2, 0);
465 471
466 snprintf(modfile, sizeof(modfile), "%s/gettext.lua", coref); 472 snprintf(modfile, sizeof(modfile), "%s/gettext.lua", coref);
467 if (elua_report_error(L, elua_progname, elua_io_loadfile(L, modfile))) 473 if (elua_report_error(elua_state, elua_progname, elua_io_loadfile(L, modfile)))
468 { 474 {
469 m->status = 1; 475 m->status = 1;
470 return 0; 476 return 0;
@@ -484,14 +490,14 @@ elua_main(lua_State *L)
484 { 490 {
485 case ARG_CODE: 491 case ARG_CODE:
486 if (!hasexec) hasexec = EINA_TRUE; 492 if (!hasexec) hasexec = EINA_TRUE;
487 if (elua_dostr(L, data->value, "=(command line)")) 493 if (elua_dostr(elua_state, data->value, "=(command line)"))
488 { 494 {
489 m->status = 1; 495 m->status = 1;
490 return 0; 496 return 0;
491 } 497 }
492 break; 498 break;
493 case ARG_LIBRARY: 499 case ARG_LIBRARY:
494 if (elua_dolib(L, data->value)) 500 if (elua_dolib(elua_state, data->value))
495 { 501 {
496 m->status = 1; 502 m->status = 1;
497 return 0; 503 return 0;
@@ -509,13 +515,13 @@ elua_main(lua_State *L)
509 if (optind < argc) 515 if (optind < argc)
510 { 516 {
511 int quit = 0; 517 int quit = 0;
512 if ((m->status = elua_doscript(L, argc, argv, optind, &quit))) return 0; 518 if ((m->status = elua_doscript(elua_state, argc, argv, optind, &quit))) return 0;
513 if (quit) return 0; 519 if (quit) return 0;
514 } 520 }
515 else if (!hasexec) 521 else if (!hasexec)
516 { 522 {
517 int quit; 523 int quit;
518 if ((m->status = elua_dofile(L, NULL))) return 0; 524 if ((m->status = elua_dofile(elua_state, NULL))) return 0;
519 quit = lua_toboolean(L, -1); 525 quit = lua_toboolean(L, -1);
520 lua_pop(L, 1); 526 lua_pop(L, 1);
521 if (quit) return 0; 527 if (quit) return 0;