summaryrefslogtreecommitdiff
path: root/ldebug.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldebug.c')
-rw-r--r--ldebug.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/ldebug.c b/ldebug.c
index dc5f78c6..a716d95e 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -34,8 +34,8 @@
#define noLuaClosure(f) ((f) == NULL || (f)->c.tt == LUA_VCCL)
-static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
- const char **name);
+static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
+ const char **name);
static int currentpc (CallInfo *ci) {
@@ -317,15 +317,9 @@ static void collectvalidlines (lua_State *L, Closure *f) {
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
- if (ci == NULL) /* no 'ci'? */
- return NULL; /* no info */
- else if (ci->callstatus & CIST_FIN) { /* is this a finalizer? */
- *name = "__gc";
- return "metamethod"; /* report it as such */
- }
- /* calling function is a known Lua function? */
- else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
- return funcnamefromcode(L, ci->previous, name);
+ /* calling function is a known function? */
+ if (ci != NULL && !(ci->callstatus & CIST_TAIL))
+ return funcnamefromcall(L, ci->previous, name);
else return NULL; /* no way to find a name */
}
@@ -597,16 +591,10 @@ static const char *getobjname (const Proto *p, int lastpc, int reg,
** Returns what the name is (e.g., "for iterator", "method",
** "metamethod") and sets '*name' to point to the name.
*/
-static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
- const char **name) {
+static const char *funcnamefromcode (lua_State *L, const Proto *p,
+ int pc, const char **name) {
TMS tm = (TMS)0; /* (initial value avoids warnings) */
- const Proto *p = ci_func(ci)->p; /* calling function */
- int pc = currentpc(ci); /* calling instruction index */
Instruction i = p->code[pc]; /* calling instruction */
- if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
- *name = "?";
- return "hook";
- }
switch (GET_OPCODE(i)) {
case OP_CALL:
case OP_TAILCALL:
@@ -643,6 +631,26 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
return "metamethod";
}
+
+/*
+** Try to find a name for a function based on how it was called.
+*/
+static const char *funcnamefromcall (lua_State *L, CallInfo *ci,
+ const char **name) {
+ if (ci->callstatus & CIST_HOOKED) { /* was it called inside a hook? */
+ *name = "?";
+ return "hook";
+ }
+ else if (ci->callstatus & CIST_FIN) { /* was it called as a finalizer? */
+ *name = "__gc";
+ return "metamethod"; /* report it as such */
+ }
+ else if (isLua(ci))
+ return funcnamefromcode(L, ci_func(ci)->p, currentpc(ci), name);
+ else
+ return NULL;
+}
+
/* }====================================================== */
@@ -728,14 +736,14 @@ l_noret luaG_typeerror (lua_State *L, const TValue *o, const char *op) {
/*
-** Raise an error for calling a non-callable object. Try to find
-** a name for the object based on the code that made the call
-** ('funcnamefromcode'); if it cannot get a name there, try 'varinfo'.
+** Raise an error for calling a non-callable object. Try to find a name
+** for the object based on how it was called ('funcnamefromcall'); if it
+** cannot get a name there, try 'varinfo'.
*/
l_noret luaG_callerror (lua_State *L, const TValue *o) {
CallInfo *ci = L->ci;
const char *name = NULL; /* to avoid warnings */
- const char *kind = (isLua(ci)) ? funcnamefromcode(L, ci, &name) : NULL;
+ const char *kind = funcnamefromcall(L, ci, &name);
const char *extra = kind ? formatvarinfo(L, kind, name) : varinfo(L, o);
typeerror(L, o, "call", extra);
}