diff -Naur lua-5.1.4/src/Makefile my-lua-changes/src/Makefile --- lua-5.1.4/src/Makefile 2008-01-19 13:37:58.000000000 -0600 +++ my-lua-changes/src/Makefile 2009-05-06 11:25:10.310376320 -0500 @@ -96,7 +96,7 @@ $(MAKE) all MYCFLAGS= linux: - $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" + $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX -DHAS_DLADDR=1" MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" macosx: $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline" diff -Naur lua-5.1.4/src/ldebug.c my-lua-changes/src/ldebug.c --- lua-5.1.4/src/ldebug.c 2008-05-08 11:56:26.000000000 -0500 +++ my-lua-changes/src/ldebug.c 2009-05-06 11:30:46.990003983 -0500 @@ -28,6 +28,11 @@ #include "ltm.h" #include "lvm.h" +#if HAS_DLADDR +# define __USE_GNU +# define _GNU_SOURCE +# include +#endif static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); @@ -149,7 +154,16 @@ static void funcinfo (lua_Debug *ar, Closure *cl) { if (cl->c.isC) { +#if HAS_DLADDR + Dl_info info; + if(dladdr(cl->c.f, &info)) { + ar->source = info.dli_fname; + } else { + ar->source = "=[C]"; + } +#else ar->source = "=[C]"; +#endif ar->linedefined = -1; ar->lastlinedefined = -1; ar->what = "C"; @@ -543,7 +557,20 @@ static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { Instruction i; - if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) + if(!isLua(ci - 1)) { +#if HAS_DLADDR + Dl_info info; + if(dladdr(ci_func(ci)->c.f, &info)) { + *name = info.dli_sname; + return "cfunction"; /* for now */ + } else { + return NULL; + } +#else + return NULL; +#endif + } + if (isLua(ci) && ci->tailcalls > 0) return NULL; /* calling function is not Lua (or is unknown) */ ci--; /* calling function */ i = ci_func(ci)->l.p->code[currentpc(L, ci)];