lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I spoke a bit too soon.  It turns out if your problem is too many
begins, you can diagnose it without help from lua, by doing some macro
hacking and using atexit(3).  For too many ends, Lua would still have
to tell you the line on which the bad end occurs.

It would be even nicer if each begin returned a cookie that had to
passed to the matching end at run time, and you could diagnose these
things instantly...


Norman

P.S.  Here's the trick:

In your header file, this:

extern char **blockfiles;
extern int *blocklines;
#define lua_beginblock() (*blockfiles++ = __FILE__, *blocklines++ = __LINE__, \
			  lua_beginblock())
#define lua_endblock() (--blockfiles, --*blocklines, lua_endblock())
extern void showall(void);


And in your main()

  atexit(showall);

and the implementation is:

static char *bfiles[1024];
static int blines[1024];
char **blockfiles = bfiles;
int *blocklines = blines;
void showall(void) {
  while (blockfiles > bfiles)
    fprintf(stderr, "Open block at %s:%d\n", *--blockfiles, *--blocklines);
}


And a sample output is:


: nr@labrador 2379 ; r ./p
./pdbconv pack locus.asc small.pdb
Database.records is table
listlength is function
3 should be 3
35 records in database
lua: `lua_beginblock': too many nested blocks
lua: exit(1). Unable to recover
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240
Open block at pdbconv.nw:240