Showing the changes to src/lua.c (1 of 37 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | −** $Id: lua.c,v 1.133 2004/11/18 19:53:49 roberto Exp $ | |
| 2 | +** $Id: lua.c,v 1.135 2005/01/10 17:21:10 roberto Exp $ | |
| 3 | 3 | ** Lua stand-alone interpreter |
| 4 | 4 | ** See Copyright Notice in lua.h |
| 5 | 5 | */ |
| @@ -79,11 +79,23 @@ static int report (lua_State *L, int status) { · 73 unmodified lines | ||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
| 82 | +static int traceback (lua_State *L) { | |
| 83 | + luaL_getfield(L, LUA_GLOBALSINDEX, "debug.traceback"); | |
| 84 | + if (!lua_isfunction(L, -1)) | |
| 85 | + lua_pop(L, 1); | |
| 86 | + else { | |
| 87 | + lua_pushvalue(L, 1); /* pass error message */ | |
| 88 | + lua_pushinteger(L, 2); /* skip this function and traceback */ | |
| 89 | + lua_call(L, 2, 1); /* call debug.traceback */ | |
| 90 | + } | |
| 91 | + return 1; | |
| 92 | +} | |
| 93 | + | |
| 94 | + | |
| 82 | 95 | static int docall (lua_State *L, int narg, int clear) { |
| 83 | 96 | int status; |
| 84 | 97 | int base = lua_gettop(L) - narg; /* function index */ |
| 85 | − lua_pushliteral(L, "_TRACEBACK"); | |
| 86 | − lua_rawget(L, LUA_GLOBALSINDEX); /* get traceback function */ | |
| 98 | + lua_pushcfunction(L, traceback); /* push traceback function */ | |
| 87 | 99 | lua_insert(L, base); /* put it under chunk and args */ |
| 88 | 100 | signal(SIGINT, laction); |
| 89 | 101 | status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); |
| @@ -359,7 +371,7 @@ static int pmain (lua_State *L) { · 269 unmodified lines | ||
| 359 | 371 | int interactive = 1; |
| 360 | 372 | if (s->argv[0] && s->argv[0][0]) progname = s->argv[0]; |
| 361 | 373 | globalL = L; |
| 362 | − lua_userinit(L); /* open libraries */ | |
| 374 | + luaopen_stdlibs(L); /* open libraries */ | |
| 363 | 375 | status = handle_luainit(L); |
| 364 | 376 | if (status == 0) { |
| 365 | 377 | status = handle_argv(L, s->argv, &interactive); |