diff options
-rw-r--r-- | lapi.c | 92 | ||||
-rw-r--r-- | ldblib.c | 4 | ||||
-rw-r--r-- | ldo.c | 107 | ||||
-rw-r--r-- | ldo.h | 14 | ||||
-rw-r--r-- | lua.c | 10 |
5 files changed, 133 insertions, 94 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.183 2002/04/05 18:54:31 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.184 2002/04/16 17:08:28 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -19,6 +19,7 @@ | |||
19 | #include "lstring.h" | 19 | #include "lstring.h" |
20 | #include "ltable.h" | 20 | #include "ltable.h" |
21 | #include "ltm.h" | 21 | #include "ltm.h" |
22 | #include "lundump.h" | ||
22 | #include "lvm.h" | 23 | #include "lvm.h" |
23 | 24 | ||
24 | 25 | ||
@@ -528,30 +529,97 @@ LUA_API void lua_rawcall (lua_State *L, int nargs, int nresults) { | |||
528 | } | 529 | } |
529 | 530 | ||
530 | 531 | ||
531 | LUA_API int lua_dofile (lua_State *L, const char *filename) { | 532 | LUA_API int lua_call (lua_State *L, int nargs, int nresults) { |
532 | int status; | 533 | int status; |
533 | status = lua_loadfile(L, filename); | 534 | int errpos = lua_gettop(L) - nargs; |
534 | if (status == 0) /* parse OK? */ | 535 | lua_getglobal(L, "_ERRORMESSAGE"); |
535 | status = lua_call(L, 0, LUA_MULTRET); /* call main */ | 536 | lua_insert(L, errpos); /* put below function and args */ |
537 | status = lua_pcall(L, nargs, nresults, errpos); | ||
538 | lua_remove(L, errpos); | ||
536 | return status; | 539 | return status; |
537 | } | 540 | } |
538 | 541 | ||
539 | 542 | ||
540 | LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, | 543 | LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errf) { |
541 | const char *name) { | ||
542 | int status; | 544 | int status; |
543 | status = lua_loadbuffer(L, buff, size, name); | 545 | const TObject *err; |
544 | if (status == 0) /* parse OK? */ | 546 | lua_lock(L); |
545 | status = lua_call(L, 0, LUA_MULTRET); /* call main */ | 547 | err = (errf == 0) ? &luaO_nilobject : luaA_index(L, errf); |
548 | status = luaD_pcall(L, nargs, nresults, err); | ||
549 | lua_unlock(L); | ||
550 | return status; | ||
551 | } | ||
552 | |||
553 | |||
554 | static int aux_do (lua_State *L, int status) { | ||
555 | if (status == 0) { /* parse OK? */ | ||
556 | int err = lua_gettop(L); | ||
557 | lua_getglobal(L, "_ERRORMESSAGE"); | ||
558 | lua_insert(L, err); | ||
559 | status = lua_pcall(L, 0, LUA_MULTRET, err); /* call main */ | ||
560 | lua_remove(L, err); /* remove error function */ | ||
561 | } | ||
546 | return status; | 562 | return status; |
547 | } | 563 | } |
548 | 564 | ||
549 | 565 | ||
566 | LUA_API int lua_dofile (lua_State *L, const char *filename) { | ||
567 | return aux_do(L, lua_loadfile(L, filename)); | ||
568 | } | ||
569 | |||
570 | |||
571 | LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, | ||
572 | const char *name) { | ||
573 | return aux_do(L, lua_loadbuffer(L, buff, size, name)); | ||
574 | } | ||
575 | |||
576 | |||
550 | LUA_API int lua_dostring (lua_State *L, const char *str) { | 577 | LUA_API int lua_dostring (lua_State *L, const char *str) { |
551 | return lua_dobuffer(L, str, strlen(str), str); | 578 | return lua_dobuffer(L, str, strlen(str), str); |
552 | } | 579 | } |
553 | 580 | ||
554 | 581 | ||
582 | LUA_API int lua_loadfile (lua_State *L, const char *filename) { | ||
583 | ZIO z; | ||
584 | int status; | ||
585 | int bin; /* flag for file mode */ | ||
586 | int nlevel; /* level on the stack of filename */ | ||
587 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); | ||
588 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ | ||
589 | bin = (ungetc(getc(f), f) == LUA_SIGNATURE[0]); | ||
590 | if (bin && f != stdin) { | ||
591 | fclose(f); | ||
592 | f = fopen(filename, "rb"); /* reopen in binary mode */ | ||
593 | if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ | ||
594 | } | ||
595 | if (filename == NULL) | ||
596 | lua_pushstring(L, "=stdin"); | ||
597 | else { | ||
598 | lua_pushliteral(L, "@"); | ||
599 | lua_pushstring(L, filename); | ||
600 | lua_concat(L, 2); | ||
601 | } | ||
602 | nlevel = lua_gettop(L); | ||
603 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ | ||
604 | luaZ_Fopen(&z, f, filename); | ||
605 | status = luaD_protectedparser(L, &z, bin); | ||
606 | if (ferror(f)) status = LUA_ERRFILE; | ||
607 | lua_remove(L, nlevel); /* remove filename */ | ||
608 | if (f != stdin) | ||
609 | fclose(f); | ||
610 | return status; | ||
611 | } | ||
612 | |||
613 | |||
614 | LUA_API int lua_loadbuffer (lua_State *L, const char *buff, size_t size, | ||
615 | const char *name) { | ||
616 | ZIO z; | ||
617 | if (!name) name = "?"; | ||
618 | luaZ_mopen(&z, buff, size, name); | ||
619 | return luaD_protectedparser(L, &z, buff[0]==LUA_SIGNATURE[0]); | ||
620 | } | ||
621 | |||
622 | |||
555 | 623 | ||
556 | /* | 624 | /* |
557 | ** Garbage-collection functions | 625 | ** Garbage-collection functions |
@@ -595,7 +663,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
595 | 663 | ||
596 | LUA_API void lua_error (lua_State *L, const char *s) { | 664 | LUA_API void lua_error (lua_State *L, const char *s) { |
597 | lua_lock(L); | 665 | lua_lock(L); |
598 | luaD_error(L, s); | 666 | luaD_runerror(L, s); |
599 | lua_unlock(L); | 667 | lua_unlock(L); |
600 | } | 668 | } |
601 | 669 | ||
@@ -662,7 +730,7 @@ LUA_API void lua_concat (lua_State *L, int n) { | |||
662 | L->top -= (n-1); | 730 | L->top -= (n-1); |
663 | luaC_checkGC(L); | 731 | luaC_checkGC(L); |
664 | } | 732 | } |
665 | else if (n == 0) { /* push null string */ | 733 | else if (n == 0) { /* push empty string */ |
666 | setsvalue(L->top, luaS_newlstr(L, NULL, 0)); | 734 | setsvalue(L->top, luaS_newlstr(L, NULL, 0)); |
667 | api_incr_top(L); | 735 | api_incr_top(L); |
668 | } | 736 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.46 2002/04/02 20:41:59 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.47 2002/04/09 19:48:08 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -265,7 +265,7 @@ static const luaL_reg dblib[] = { | |||
265 | 265 | ||
266 | LUALIB_API int lua_dblibopen (lua_State *L) { | 266 | LUALIB_API int lua_dblibopen (lua_State *L) { |
267 | luaL_opennamedlib(L, "dbg", dblib, 0); | 267 | luaL_opennamedlib(L, "dbg", dblib, 0); |
268 | lua_register(L, LUA_ERRORMESSAGE, errorfb); | 268 | lua_register(L, "_ERRORMESSAGE", errorfb); |
269 | return 0; | 269 | return 0; |
270 | } | 270 | } |
271 | 271 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.170 2002/04/15 19:34:42 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.171 2002/04/16 17:08:28 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -38,9 +38,11 @@ struct lua_longjmp { | |||
38 | jmp_buf b; | 38 | jmp_buf b; |
39 | int allowhooks; /* `allowhook' state when protection was set */ | 39 | int allowhooks; /* `allowhook' state when protection was set */ |
40 | volatile int status; /* error code */ | 40 | volatile int status; /* error code */ |
41 | TObject err; /* function to be called in case of errors */ | ||
41 | }; | 42 | }; |
42 | 43 | ||
43 | 44 | ||
45 | |||
44 | static void correctstack (lua_State *L, TObject *oldstack) { | 46 | static void correctstack (lua_State *L, TObject *oldstack) { |
45 | struct lua_longjmp *lj; | 47 | struct lua_longjmp *lj; |
46 | CallInfo *ci; | 48 | CallInfo *ci; |
@@ -108,11 +110,11 @@ void luaD_growstack (lua_State *L, int n) { | |||
108 | static void luaD_growCI (lua_State *L) { | 110 | static void luaD_growCI (lua_State *L) { |
109 | L->ci--; | 111 | L->ci--; |
110 | if (L->size_ci > LUA_MAXCALLS) /* overflow while handling overflow? */ | 112 | if (L->size_ci > LUA_MAXCALLS) /* overflow while handling overflow? */ |
111 | luaD_breakrun(L, LUA_ERRERR); /* break run without error message */ | 113 | luaD_error(L, NULL, LUA_ERRERR); /* break run without error message */ |
112 | else { | 114 | else { |
113 | luaD_reallocCI(L, 2*L->size_ci); | 115 | luaD_reallocCI(L, 2*L->size_ci); |
114 | if (L->size_ci > LUA_MAXCALLS) | 116 | if (L->size_ci > LUA_MAXCALLS) |
115 | luaD_error(L, "stack overflow"); | 117 | luaD_runerror(L, "stack overflow"); |
116 | } | 118 | } |
117 | L->ci++; | 119 | L->ci++; |
118 | } | 120 | } |
@@ -278,7 +280,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) { | |||
278 | firstResult = luaV_execute(L); /* call it */ | 280 | firstResult = luaV_execute(L); /* call it */ |
279 | if (firstResult == NULL) { | 281 | if (firstResult == NULL) { |
280 | luaD_poscall(L, 0, L->top); | 282 | luaD_poscall(L, 0, L->top); |
281 | luaD_error(L, "attempt to `yield' across tag-method/C-call boundary"); | 283 | luaD_runerror(L, "attempt to `yield' across tag-method/C-call boundary"); |
282 | } | 284 | } |
283 | } | 285 | } |
284 | luaD_poscall(L, nResults, firstResult); | 286 | luaD_poscall(L, nResults, firstResult); |
@@ -325,14 +327,17 @@ static void resume (lua_State *L, void *numres) { | |||
325 | LUA_API int lua_resume (lua_State *L, lua_State *co) { | 327 | LUA_API int lua_resume (lua_State *L, lua_State *co) { |
326 | CallInfo *ci; | 328 | CallInfo *ci; |
327 | int numres; | 329 | int numres; |
330 | TObject o; | ||
328 | int status; | 331 | int status; |
329 | lua_lock(L); | 332 | lua_lock(L); |
330 | ci = co->ci; | 333 | ci = co->ci; |
331 | if (ci == co->base_ci) /* no activation record? ?? */ | 334 | if (ci == co->base_ci) /* no activation record? ?? */ |
332 | luaD_error(L, "thread is dead - cannot be resumed"); | 335 | luaD_runerror(L, "thread is dead - cannot be resumed"); |
333 | if (co->errorJmp != NULL) /* ?? */ | 336 | if (co->errorJmp != NULL) /* ?? */ |
334 | luaD_error(L, "thread is active - cannot be resumed"); | 337 | luaD_runerror(L, "thread is active - cannot be resumed"); |
335 | status = luaD_runprotected(co, resume, &numres); | 338 | setsvalue(&o, luaS_newliteral(L, "_ERRORMESSAGE")); |
339 | luaV_gettable(L, gt(L), &o, &o); | ||
340 | status = luaD_runprotected(co, resume, &o, &numres); | ||
336 | if (status == 0) | 341 | if (status == 0) |
337 | move_results(L, co->top - numres, co->top); | 342 | move_results(L, co->top - numres, co->top); |
338 | lua_unlock(L); | 343 | lua_unlock(L); |
@@ -345,7 +350,7 @@ LUA_API int lua_yield (lua_State *L, int nresults) { | |||
345 | lua_lock(L); | 350 | lua_lock(L); |
346 | ci = L->ci; | 351 | ci = L->ci; |
347 | if (ci_func(ci-1)->c.isC) | 352 | if (ci_func(ci-1)->c.isC) |
348 | luaD_error(L, "cannot `yield' a C function"); | 353 | luaD_runerror(L, "cannot `yield' a C function"); |
349 | ci->yield_results = nresults; | 354 | ci->yield_results = nresults; |
350 | lua_unlock(L); | 355 | lua_unlock(L); |
351 | return -1; | 356 | return -1; |
@@ -360,24 +365,23 @@ struct CallS { /* data to `f_call' */ | |||
360 | int nresults; | 365 | int nresults; |
361 | }; | 366 | }; |
362 | 367 | ||
368 | |||
363 | static void f_call (lua_State *L, void *ud) { | 369 | static void f_call (lua_State *L, void *ud) { |
364 | struct CallS *c = cast(struct CallS *, ud); | 370 | struct CallS *c = cast(struct CallS *, ud); |
365 | luaD_call(L, c->func, c->nresults); | 371 | luaD_call(L, c->func, c->nresults); |
366 | } | 372 | } |
367 | 373 | ||
368 | 374 | ||
369 | LUA_API int lua_call (lua_State *L, int nargs, int nresults) { | 375 | int luaD_pcall (lua_State *L, int nargs, int nresults, const TObject *err) { |
370 | struct CallS c; | 376 | struct CallS c; |
371 | int status; | 377 | int status; |
372 | lua_lock(L); | ||
373 | c.func = L->top - (nargs+1); /* function to be called */ | 378 | c.func = L->top - (nargs+1); /* function to be called */ |
374 | c.nresults = nresults; | 379 | c.nresults = nresults; |
375 | status = luaD_runprotected(L, f_call, &c); | 380 | status = luaD_runprotected(L, &f_call, err, &c); |
376 | if (status != 0) { /* an error occurred? */ | 381 | if (status != 0) { /* an error occurred? */ |
377 | L->top -= nargs+1; /* remove parameters and func from the stack */ | 382 | L->top -= nargs+1; /* remove parameters and func from the stack */ |
378 | luaF_close(L, L->top); /* close eventual pending closures */ | 383 | luaF_close(L, L->top); /* close eventual pending closures */ |
379 | } | 384 | } |
380 | lua_unlock(L); | ||
381 | return status; | 385 | return status; |
382 | } | 386 | } |
383 | 387 | ||
@@ -400,8 +404,9 @@ static void f_parser (lua_State *L, void *ud) { | |||
400 | } | 404 | } |
401 | 405 | ||
402 | 406 | ||
403 | static int protectedparser (lua_State *L, ZIO *z, int bin) { | 407 | int luaD_protectedparser (lua_State *L, ZIO *z, int bin) { |
404 | struct SParser p; | 408 | struct SParser p; |
409 | TObject o; | ||
405 | lu_mem old_blocks; | 410 | lu_mem old_blocks; |
406 | int status; | 411 | int status; |
407 | lua_lock(L); | 412 | lua_lock(L); |
@@ -410,7 +415,9 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
410 | if (G(L)->nblocks/8 >= G(L)->GCthreshold/10) | 415 | if (G(L)->nblocks/8 >= G(L)->GCthreshold/10) |
411 | luaC_collectgarbage(L); | 416 | luaC_collectgarbage(L); |
412 | old_blocks = G(L)->nblocks; | 417 | old_blocks = G(L)->nblocks; |
413 | status = luaD_runprotected(L, f_parser, &p); | 418 | setsvalue(&o, luaS_newliteral(L, "_ERRORMESSAGE")); |
419 | luaV_gettable(L, gt(L), &o, &o); | ||
420 | status = luaD_runprotected(L, f_parser, &o, &p); | ||
414 | if (status == 0) { | 421 | if (status == 0) { |
415 | /* add new memory to threshold (as it probably will stay) */ | 422 | /* add new memory to threshold (as it probably will stay) */ |
416 | lua_assert(G(L)->nblocks >= old_blocks); | 423 | lua_assert(G(L)->nblocks >= old_blocks); |
@@ -423,47 +430,6 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) { | |||
423 | } | 430 | } |
424 | 431 | ||
425 | 432 | ||
426 | LUA_API int lua_loadfile (lua_State *L, const char *filename) { | ||
427 | ZIO z; | ||
428 | int status; | ||
429 | int bin; /* flag for file mode */ | ||
430 | int nlevel; /* level on the stack of filename */ | ||
431 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); | ||
432 | if (f == NULL) return LUA_ERRFILE; /* unable to open file */ | ||
433 | bin = (ungetc(getc(f), f) == LUA_SIGNATURE[0]); | ||
434 | if (bin && f != stdin) { | ||
435 | fclose(f); | ||
436 | f = fopen(filename, "rb"); /* reopen in binary mode */ | ||
437 | if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ | ||
438 | } | ||
439 | if (filename == NULL) | ||
440 | lua_pushstring(L, "=stdin"); | ||
441 | else { | ||
442 | lua_pushliteral(L, "@"); | ||
443 | lua_pushstring(L, filename); | ||
444 | lua_concat(L, 2); | ||
445 | } | ||
446 | nlevel = lua_gettop(L); | ||
447 | filename = lua_tostring(L, -1); /* filename = `@'..filename */ | ||
448 | luaZ_Fopen(&z, f, filename); | ||
449 | status = protectedparser(L, &z, bin); | ||
450 | if (ferror(f)) status = LUA_ERRFILE; | ||
451 | lua_remove(L, nlevel); /* remove filename */ | ||
452 | if (f != stdin) | ||
453 | fclose(f); | ||
454 | return status; | ||
455 | } | ||
456 | |||
457 | |||
458 | LUA_API int lua_loadbuffer (lua_State *L, const char *buff, size_t size, | ||
459 | const char *name) { | ||
460 | ZIO z; | ||
461 | if (!name) name = "?"; | ||
462 | luaZ_mopen(&z, buff, size, name); | ||
463 | return protectedparser(L, &z, buff[0]==LUA_SIGNATURE[0]); | ||
464 | } | ||
465 | |||
466 | |||
467 | 433 | ||
468 | /* | 434 | /* |
469 | ** {====================================================== | 435 | ** {====================================================== |
@@ -472,16 +438,14 @@ LUA_API int lua_loadbuffer (lua_State *L, const char *buff, size_t size, | |||
472 | */ | 438 | */ |
473 | 439 | ||
474 | 440 | ||
475 | static void message (lua_State *L, const char *s) { | 441 | static void message (lua_State *L, const char *msg) { |
476 | TObject o, m; | 442 | TObject *m = &L->errorJmp->err; |
477 | setsvalue(&o, luaS_newliteral(L, LUA_ERRORMESSAGE)); | 443 | if (ttype(m) == LUA_TFUNCTION) { |
478 | luaV_gettable(L, gt(L), &o, &m); | 444 | setobj(L->top, m); |
479 | if (ttype(&m) == LUA_TFUNCTION) { | ||
480 | setobj(L->top, &m); | ||
481 | incr_top(L); | 445 | incr_top(L); |
482 | setsvalue(L->top, luaS_new(L, s)); | 446 | setsvalue(L->top, luaS_new(L, msg)); |
483 | incr_top(L); | 447 | incr_top(L); |
484 | luaD_call(L, L->top-2, 0); | 448 | luaD_call(L, L->top - 2, 0); |
485 | } | 449 | } |
486 | } | 450 | } |
487 | 451 | ||
@@ -489,15 +453,10 @@ static void message (lua_State *L, const char *s) { | |||
489 | /* | 453 | /* |
490 | ** Reports an error, and jumps up to the available recovery label | 454 | ** Reports an error, and jumps up to the available recovery label |
491 | */ | 455 | */ |
492 | void luaD_error (lua_State *L, const char *s) { | 456 | void luaD_error (lua_State *L, const char *s, int errcode) { |
493 | if (s) message(L, s); | ||
494 | luaD_breakrun(L, LUA_ERRRUN); | ||
495 | } | ||
496 | |||
497 | |||
498 | void luaD_breakrun (lua_State *L, int errcode) { | ||
499 | if (L->errorJmp) { | 457 | if (L->errorJmp) { |
500 | L->errorJmp->status = errcode; | 458 | L->errorJmp->status = errcode; |
459 | if (s) message(L, s); | ||
501 | longjmp(L->errorJmp->b, 1); | 460 | longjmp(L->errorJmp->b, 1); |
502 | } | 461 | } |
503 | else { | 462 | else { |
@@ -507,12 +466,18 @@ void luaD_breakrun (lua_State *L, int errcode) { | |||
507 | } | 466 | } |
508 | 467 | ||
509 | 468 | ||
510 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud) { | 469 | void luaD_runerror (lua_State *L, const char *s) { |
470 | luaD_error(L, s, LUA_ERRRUN); | ||
471 | } | ||
472 | |||
473 | |||
474 | int luaD_runprotected (lua_State *L, Pfunc f, const TObject *err, void *ud) { | ||
511 | struct lua_longjmp lj; | 475 | struct lua_longjmp lj; |
512 | lj.ci = L->ci; | 476 | lj.ci = L->ci; |
513 | lj.top = L->top; | 477 | lj.top = L->top; |
514 | lj.allowhooks = L->allowhooks; | 478 | lj.allowhooks = L->allowhooks; |
515 | lj.status = 0; | 479 | lj.status = 0; |
480 | lj.err = *err; | ||
516 | lj.previous = L->errorJmp; /* chain new error handler */ | 481 | lj.previous = L->errorJmp; /* chain new error handler */ |
517 | L->errorJmp = &lj; | 482 | L->errorJmp = &lj; |
518 | if (setjmp(lj.b) == 0) | 483 | if (setjmp(lj.b) == 0) |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.h,v 1.41 2002/03/20 12:52:32 roberto Exp roberto $ | 2 | ** $Id: ldo.h,v 1.42 2002/03/25 17:47:14 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -10,6 +10,7 @@ | |||
10 | 10 | ||
11 | #include "lobject.h" | 11 | #include "lobject.h" |
12 | #include "lstate.h" | 12 | #include "lstate.h" |
13 | #include "lzio.h" | ||
13 | 14 | ||
14 | 15 | ||
15 | /* | 16 | /* |
@@ -27,17 +28,22 @@ | |||
27 | #define restorestack(L,n) ((TObject *)((char *)L->stack + (n))) | 28 | #define restorestack(L,n) ((TObject *)((char *)L->stack + (n))) |
28 | 29 | ||
29 | 30 | ||
31 | /* type of protected functions, to be ran by `runprotected' */ | ||
32 | typedef void (*Pfunc) (lua_State *L, void *v); | ||
33 | |||
34 | int luaD_protectedparser (lua_State *L, ZIO *z, int bin); | ||
30 | void luaD_lineHook (lua_State *L, int line); | 35 | void luaD_lineHook (lua_State *L, int line); |
31 | StkId luaD_precall (lua_State *L, StkId func); | 36 | StkId luaD_precall (lua_State *L, StkId func); |
32 | void luaD_call (lua_State *L, StkId func, int nResults); | 37 | void luaD_call (lua_State *L, StkId func, int nResults); |
38 | int luaD_pcall (lua_State *L, int nargs, int nresults, const TObject *err); | ||
33 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult); | 39 | void luaD_poscall (lua_State *L, int wanted, StkId firstResult); |
34 | void luaD_reallocCI (lua_State *L, int newsize); | 40 | void luaD_reallocCI (lua_State *L, int newsize); |
35 | void luaD_reallocstack (lua_State *L, int newsize); | 41 | void luaD_reallocstack (lua_State *L, int newsize); |
36 | void luaD_growstack (lua_State *L, int n); | 42 | void luaD_growstack (lua_State *L, int n); |
37 | 43 | ||
38 | void luaD_error (lua_State *L, const char *s); | 44 | void luaD_error (lua_State *L, const char *s, int errcode); |
39 | void luaD_breakrun (lua_State *L, int errcode); | 45 | void luaD_runerror (lua_State *L, const char *s); |
40 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud); | 46 | int luaD_runprotected (lua_State *L, Pfunc f, const TObject *err, void *ud); |
41 | 47 | ||
42 | 48 | ||
43 | #endif | 49 | #endif |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.81 2002/04/05 18:54:31 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.82 2002/04/09 20:19:06 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -200,16 +200,16 @@ static int trap_eof (lua_State *l) { | |||
200 | 200 | ||
201 | 201 | ||
202 | static int load_string (void) { | 202 | static int load_string (void) { |
203 | lua_getglobal(L, LUA_ERRORMESSAGE); | 203 | lua_getglobal(L, "_ERRORMESSAGE"); |
204 | lua_pushvalue(L, 1); | 204 | lua_pushvalue(L, 1); |
205 | lua_setglobal(L, LUA_ERRORMESSAGE); | 205 | lua_setglobal(L, "_ERRORMESSAGE"); |
206 | incomplete = 0; | 206 | incomplete = 0; |
207 | for (;;) { /* repeat until gets a complete line */ | 207 | for (;;) { /* repeat until gets a complete line */ |
208 | int result; | 208 | int result; |
209 | char *buffer = readline(get_prompt(incomplete)); | 209 | char *buffer = readline(get_prompt(incomplete)); |
210 | if (buffer == NULL) { /* input end? */ | 210 | if (buffer == NULL) { /* input end? */ |
211 | lua_settop(L, 2); | 211 | lua_settop(L, 2); |
212 | lua_setglobal(L, LUA_ERRORMESSAGE); | 212 | lua_setglobal(L, "_ERRORMESSAGE"); |
213 | return 0; | 213 | return 0; |
214 | } | 214 | } |
215 | if (!incomplete && buffer[0] == '=') { | 215 | if (!incomplete && buffer[0] == '=') { |
@@ -225,7 +225,7 @@ static int load_string (void) { | |||
225 | lua_remove(L, 3); | 225 | lua_remove(L, 3); |
226 | if (result == 0) { | 226 | if (result == 0) { |
227 | lua_insert(L, 2); /* swap compiled chunk with old _ERRORMESSAGE */ | 227 | lua_insert(L, 2); /* swap compiled chunk with old _ERRORMESSAGE */ |
228 | lua_setglobal(L, LUA_ERRORMESSAGE); /* restore old _ERRORMESSAGE */ | 228 | lua_setglobal(L, "_ERRORMESSAGE"); /* restore old _ERRORMESSAGE */ |
229 | return 1; | 229 | return 1; |
230 | } | 230 | } |
231 | else | 231 | else |