static void addinfo (lua_State *L, const char *msg) { CallInfo *ci = L->ci; if (isLua(ci)) { /* is Lua code? */ char buff[LUA_IDSIZE]; /* add file:line information */ int line = currentline(L, ci); luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); } }
/* * External (config file) error. Complain, using current file * and line number. */ void cfgerror(const char *fmt, ...) { va_list ap; extern const char *yyfile; va_start(ap, fmt); cfgvxerror(yyfile, currentline(), fmt, ap); va_end(ap); }
l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { CallInfo *ci = L->ci; const char *msg; va_list argp; va_start(argp, fmt); msg = luaO_pushvfstring(L, fmt, argp); /* format message */ va_end(argp); if (isLua(ci)) /* if Lua function, add source:line information */ luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci)); luaG_errormsg(L); }
static void addinfo (lua_State *L, const char *msg) { CallInfo *ci = L->ci; if (isLua(ci)) { /* is Lua code? */ char buff[LUA_IDSIZE]; /* add file:line information */ int line = currentline(ci); TString *src = ci_func(ci)->p->source; if (src) luaO_chunkid(buff, getstr(src), LUA_IDSIZE); else { /* no source available; use "?" instead */ buff[0] = '?'; buff[1] = '\0'; } luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); } }
static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, Closure *f, CallInfo *ci) { int status = 1; for (; *what; what++) { switch (*what) { case 'S': { funcinfo(ar, f); break; } case 'l': { ar->currentline = (ci && isLua(ci)) ? currentline(ci) : -1; break; } case 'u': { ar->nups = (f == NULL) ? 0 : f->c.nupvalues; if (noLuaClosure(f)) { ar->isvararg = 1; ar->nparams = 0; } else { ar->isvararg = f->l.p->is_vararg; ar->nparams = f->l.p->numparams; } break; } case 't': { ar->istailcall = (ci) ? ci->callstatus & CIST_TAIL : 0; break; } case 'n': { /* calling function is a known Lua function? */ if (ci && !(ci->callstatus & CIST_TAIL) && isLua(ci->previous)) ar->namewhat = getfuncname(L, ci->previous, &ar->name); else ar->namewhat = NULL; if (ar->namewhat == NULL) { ar->namewhat = ""; /* not found */ ar->name = NULL; } break; } case 'L': case 'f': /* handled by lua_getinfo */ break; default: status = 0; /* invalid option */ } } return status; }
l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { CallInfo *ci = L->ci; const char *msg; va_list argp; va_start(argp, fmt); msg = luaO_pushvfstring(L, fmt, argp); /* format message */ va_end(argp); if (isLua(ci)) /* if Lua function, add source:line information */ luaG_addinfo(L, msg, ci_func(ci)->p->source, currentline(ci)); #if LUA_TILDE_DEBUGGER if (L->hookmask & LUA_MASKERROR) luaD_hook(L, LUA_HOOKERROR, -1); #endif /* LUA_TILDE_DEBUGGER */ luaG_errormsg(L); }
static int auxgetinfo(lua_State* L, const char* what, lua_Debug* ar, Closure* f, CallInfo* ci) { int status = 1; if (f == NULL) { info_tailcall(ar); return status; } for (; *what; what++) { switch (*what) { case 'S': { funcinfo(ar, f); break; } case 'l': { ar->currentline = (ci) ? currentline(L, ci) : -1; break; } case 'u': { ar->nups = f->c.nupvalues; break; } case 'n': { ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; if (ar->namewhat == NULL) { ar->namewhat = ""; /* not found */ ar->name = NULL; } break; } case 'L': case 'f': /* handled by lua_getinfo */ break; default: status = 0; /* invalid option */ } } return status; }
static int auxgetinfo(lua_State * L, const char *what, lua_Debug * ar, StkId f, CallInfo * ci) { int status = 1; for (; *what; what++) { switch (*what) { case 'S': { funcinfo(ar, f); break; } case 'l': { ar->currentline = (ci) ? currentline(ci) : -1; break; } case 'u': { ar->nups = clvalue(f)->c.nupvalues; break; } case 'n': { ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL; if (ar->namewhat == NULL) { /* try to find a global name */ if ((ar->name = travglobals(L, f)) != NULL) ar->namewhat = "global"; else ar->namewhat = ""; /* not found */ } break; } case 'f': { setobj2s(L->top, f); break; } default: status = 0; /* invalid option */ } } return status; }
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { StkId func; int isactive = (*what != '>'); if (isactive) func = ar->_func; else { what++; /* skip the '>' */ func = L->top - 1; } for (; *what; what++) { switch (*what) { case 'S': { funcinfo(L, ar, func); break; } case 'l': { ar->currentline = currentline(func); break; } case 'u': { ar->nups = nups(func); break; } case 'n': { ar->namewhat = (isactive) ? getfuncname(L, func, &ar->name) : NULL; if (ar->namewhat == NULL) getname(L, func, ar); break; } case 'f': { setnormalized(L->top, func); incr_top; /* push function */ break; } default: return 0; /* invalid option */ } } if (!isactive) L->top--; /* pop function */ return 1; }
void addfile(struct nvlist *nvpath, struct nvlist *optx, int flags, const char *rule, const char *lintrule) { struct files *fi; const char *dotp, *dotp1, *tail, *path, *tail1 = NULL; struct nvlist *nv; size_t baselen; int needc, needf; char base[200]; /* check various errors */ needc = flags & FI_NEEDSCOUNT; needf = flags & FI_NEEDSFLAG; if (needc && needf) { error("cannot mix needs-count and needs-flag"); goto bad; } if (optx == NULL && (needc || needf)) { error("nothing to %s for %s", needc ? "count" : "flag", path); goto bad; } for (nv = nvpath; nv; nv = nv->nv_next) { path = nv->nv_name; /* find last part of pathname, and same without trailing suffix */ tail = strrchr(path, '/'); if (tail == NULL) tail = path; else tail++; dotp = strrchr(tail, '.'); if (dotp == NULL || dotp[1] == 0 || (baselen = dotp - tail) >= sizeof(base)) { error("invalid pathname `%s'", path); goto bad; } /* * Ensure all tailnames are identical, because .o * filenames must be identical too. */ if (tail1 && (dotp - tail != dotp1 - tail1 || strncmp(tail1, tail, dotp - tail))) error("different production from %s %s", nvpath->nv_name, tail); tail1 = tail; dotp1 = dotp; } /* * Commit this file to memory. We will decide later whether it * will be used after all. */ fi = emalloc(sizeof *fi); if (ht_insert(pathtab, path, fi)) { free(fi); if ((fi = ht_lookup(pathtab, path)) == NULL) panic("addfile: ht_lookup(%s)", path); error("duplicate file %s", path); xerror(fi->fi_srcfile, fi->fi_srcline, "here is the original definition"); } memcpy(base, tail, baselen); base[baselen] = 0; fi->fi_next = NULL; fi->fi_srcfile = yyfile; fi->fi_srcline = currentline(); fi->fi_flags = flags; fi->fi_nvpath = nvpath; fi->fi_base = intern(base); fi->fi_optx = optx; fi->fi_optf = NULL; fi->fi_mkrule[0] = rule; fi->fi_mkrule[1] = lintrule; *nextfile = fi; nextfile = &fi->fi_next; return; bad: expr_free(optx); }