diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-11-29 13:55:08 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-11-29 13:55:08 -0200 |
commit | 3617e04e972417144169d28184188a082eb40cbb (patch) | |
tree | 16741a6a01385963b2ce70cfd01fd917f9b21148 /ldo.c | |
parent | 8c62bde36fe129454bc818b5ee073267f93fe4ab (diff) | |
download | lua-3617e04e972417144169d28184188a082eb40cbb.tar.gz lua-3617e04e972417144169d28184188a082eb40cbb.tar.bz2 lua-3617e04e972417144169d28184188a082eb40cbb.zip |
'lua_load' has an extra argument 'mode'
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.100 2011/09/12 20:33:03 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.101 2011/10/07 20:45:19 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 | */ |
@@ -611,18 +611,34 @@ struct SParser { /* data to `f_parser' */ | |||
611 | ZIO *z; | 611 | ZIO *z; |
612 | Mbuffer buff; /* dynamic structure used by the scanner */ | 612 | Mbuffer buff; /* dynamic structure used by the scanner */ |
613 | Dyndata dyd; /* dynamic structures used by the parser */ | 613 | Dyndata dyd; /* dynamic structures used by the parser */ |
614 | const char *mode; | ||
614 | const char *name; | 615 | const char *name; |
615 | }; | 616 | }; |
616 | 617 | ||
618 | |||
619 | static void checkmode (lua_State *L, const char *mode, const char *x) { | ||
620 | if (mode && strchr(mode, x[0]) == NULL) { | ||
621 | luaO_pushfstring(L, | ||
622 | "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode); | ||
623 | luaD_throw(L, LUA_ERRSYNTAX); | ||
624 | } | ||
625 | } | ||
626 | |||
627 | |||
617 | static void f_parser (lua_State *L, void *ud) { | 628 | static void f_parser (lua_State *L, void *ud) { |
618 | int i; | 629 | int i; |
619 | Proto *tf; | 630 | Proto *tf; |
620 | Closure *cl; | 631 | Closure *cl; |
621 | struct SParser *p = cast(struct SParser *, ud); | 632 | struct SParser *p = cast(struct SParser *, ud); |
622 | int c = zgetc(p->z); /* read first character */ | 633 | int c = zgetc(p->z); /* read first character */ |
623 | tf = (c == LUA_SIGNATURE[0]) | 634 | if (c == LUA_SIGNATURE[0]) { |
624 | ? luaU_undump(L, p->z, &p->buff, p->name) | 635 | checkmode(L, p->mode, "binary"); |
625 | : luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); | 636 | tf = luaU_undump(L, p->z, &p->buff, p->name); |
637 | } | ||
638 | else { | ||
639 | checkmode(L, p->mode, "text"); | ||
640 | tf = luaY_parser(L, p->z, &p->buff, &p->dyd, p->name, c); | ||
641 | } | ||
626 | setptvalue2s(L, L->top, tf); | 642 | setptvalue2s(L, L->top, tf); |
627 | incr_top(L); | 643 | incr_top(L); |
628 | cl = luaF_newLclosure(L, tf); | 644 | cl = luaF_newLclosure(L, tf); |
@@ -632,11 +648,12 @@ static void f_parser (lua_State *L, void *ud) { | |||
632 | } | 648 | } |
633 | 649 | ||
634 | 650 | ||
635 | int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { | 651 | int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, |
652 | const char *mode) { | ||
636 | struct SParser p; | 653 | struct SParser p; |
637 | int status; | 654 | int status; |
638 | L->nny++; /* cannot yield during parsing */ | 655 | L->nny++; /* cannot yield during parsing */ |
639 | p.z = z; p.name = name; | 656 | p.z = z; p.name = name; p.mode = mode; |
640 | p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; | 657 | p.dyd.actvar.arr = NULL; p.dyd.actvar.size = 0; |
641 | p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; | 658 | p.dyd.gt.arr = NULL; p.dyd.gt.size = 0; |
642 | p.dyd.label.arr = NULL; p.dyd.label.size = 0; | 659 | p.dyd.label.arr = NULL; p.dyd.label.size = 0; |