aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/lapi.c b/lapi.c
index 42ed4a82..1bc5f340 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,11 +1,10 @@
1/* 1/*
2** $Id: lapi.c,v 1.185 2002/04/22 14:40:50 roberto Exp roberto $ 2** $Id: lapi.c,v 1.186 2002/05/01 20:48:12 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*/
6 6
7 7
8#include <errno.h>
9#include <stdio.h> 8#include <stdio.h>
10#include <string.h> 9#include <string.h>
11 10
@@ -31,6 +30,11 @@ const char lua_ident[] =
31 "$URL: www.lua.org $\n"; 30 "$URL: www.lua.org $\n";
32 31
33 32
33#ifndef lua_filerror
34#include <errno.h>
35#define lua_fileerror (strerror(errno))
36#endif
37
34 38
35#ifndef api_check 39#ifndef api_check
36#define api_check(L, o) ((void)1) 40#define api_check(L, o) ((void)1)
@@ -543,15 +547,19 @@ LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errf) {
543 547
544 548
545static int errfile (lua_State *L, const char *filename) { 549static int errfile (lua_State *L, const char *filename) {
546 char buff[150]; 550 if (filename == NULL) filename = "stdin";
547 sprintf(buff, "cannot read file `%.80s' (%.40s)", filename, strerror(errno)); 551 lua_pushliteral(L, "cannot read ");
548 lua_pushstring(L, buff); 552 lua_pushstring(L, filename);
553 lua_pushliteral(L, ": ");
554 lua_pushstring(L, lua_fileerror);
555 lua_concat(L, 4);
549 return LUA_ERRFILE; 556 return LUA_ERRFILE;
550} 557}
551 558
552 559
553LUA_API int lua_loadfile (lua_State *L, const char *filename) { 560LUA_API int lua_loadfile (lua_State *L, const char *filename) {
554 ZIO z; 561 ZIO z;
562 const char *luafname; /* name used by lua */
555 int status; 563 int status;
556 int bin; /* flag for file mode */ 564 int bin; /* flag for file mode */
557 int nlevel; /* level on the stack of filename */ 565 int nlevel; /* level on the stack of filename */
@@ -571,8 +579,8 @@ LUA_API int lua_loadfile (lua_State *L, const char *filename) {
571 lua_concat(L, 2); 579 lua_concat(L, 2);
572 } 580 }
573 nlevel = lua_gettop(L); 581 nlevel = lua_gettop(L);
574 filename = lua_tostring(L, -1); /* filename = `@'..filename */ 582 luafname = lua_tostring(L, -1); /* luafname = `@'..filename */
575 luaZ_Fopen(&z, f, filename); 583 luaZ_Fopen(&z, f, luafname);
576 status = luaD_protectedparser(L, &z, bin); 584 status = luaD_protectedparser(L, &z, bin);
577 if (ferror(f)) 585 if (ferror(f))
578 return errfile(L, filename); 586 return errfile(L, filename);