diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-01-13 13:56:03 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-01-13 13:56:03 -0200 |
commit | 46ec57cbc6dfe8df707be8f1fa52146988013feb (patch) | |
tree | 9d5a08bbcc0c515f80475f30f3a6e4f933df0dd4 /ldo.c | |
parent | 62787f1b1f9bb745afbf28b04241c9020a74b7a2 (diff) | |
download | lua-46ec57cbc6dfe8df707be8f1fa52146988013feb.tar.gz lua-46ec57cbc6dfe8df707be8f1fa52146988013feb.tar.bz2 lua-46ec57cbc6dfe8df707be8f1fa52146988013feb.zip |
little change when calling tag methods
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 36 |
1 files changed, 15 insertions, 21 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.63 1999/12/30 18:28:40 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.64 1999/12/30 18:40:57 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 | */ |
@@ -353,9 +353,10 @@ static int do_main (lua_State *L, ZIO *z, int bin) { | |||
353 | void luaD_gcIM (lua_State *L, const TObject *o) { | 353 | void luaD_gcIM (lua_State *L, const TObject *o) { |
354 | const TObject *im = luaT_getimbyObj(L, o, IM_GC); | 354 | const TObject *im = luaT_getimbyObj(L, o, IM_GC); |
355 | if (ttype(im) != LUA_T_NIL) { | 355 | if (ttype(im) != LUA_T_NIL) { |
356 | *L->top = *o; | 356 | luaD_checkstack(L, 2); |
357 | incr_top; | 357 | *(L->top++) = *im; |
358 | luaD_callTM(L, im, 1, 0); | 358 | *(L->top++) = *o; |
359 | luaD_call(L, L->top-2, 0); | ||
359 | } | 360 | } |
360 | } | 361 | } |
361 | 362 | ||
@@ -365,25 +366,18 @@ void luaD_gcIM (lua_State *L, const TObject *o) { | |||
365 | int lua_dofile (lua_State *L, const char *filename) { | 366 | int lua_dofile (lua_State *L, const char *filename) { |
366 | ZIO z; | 367 | ZIO z; |
367 | int status; | 368 | int status; |
368 | int bin; | 369 | int bin; /* flag for file mode */ |
370 | int c; /* look ahead char */ | ||
369 | char source[MAXFILENAME]; | 371 | char source[MAXFILENAME]; |
370 | FILE *f; | 372 | FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); |
373 | if (f == NULL) return 2; /* unable to open file */ | ||
371 | luaL_filesource(source, filename, sizeof(source)); | 374 | luaL_filesource(source, filename, sizeof(source)); |
372 | if (filename == NULL) { | 375 | c = fgetc(f); |
373 | f = stdin; | 376 | ungetc(c, f); |
374 | bin = 0; /* cannot handle stdin as a binary file */ | 377 | bin = (c == ID_CHUNK); |
375 | } | 378 | if (bin && f != stdin) { |
376 | else { | 379 | f = freopen(filename, "rb", f); /* set binary mode */ |
377 | int c; | 380 | if (f == NULL) return 2; /* unable to reopen file */ |
378 | f = fopen(filename, "r"); | ||
379 | if (f == NULL) return 2; /* unable to open file */ | ||
380 | c = fgetc(f); | ||
381 | ungetc(c, f); | ||
382 | bin = (c == ID_CHUNK); | ||
383 | if (bin) { | ||
384 | f = freopen(filename, "rb", f); /* set binary mode */ | ||
385 | if (f == NULL) return 2; /* unable to reopen file */ | ||
386 | } | ||
387 | } | 381 | } |
388 | luaZ_Fopen(&z, f, source); | 382 | luaZ_Fopen(&z, f, source); |
389 | status = do_main(L, &z, bin); | 383 | status = do_main(L, &z, bin); |