lua-users home
lua-l archive

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


Hello,

I'm experiencing some trouble with the current check_exp implementation. When Lua asserts are enabled it's defined as follows:

llimits.h:

#define check_exp(c,e)      (lua_assert(c), (e))

Then you use it in the this definition:

lobject.h

#define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c)

Which in turn is used this way:

lapi.c@75:

CClosure *func = clCvalue(ci->func);

In the end, that line (and some others in that file) is replaced by something like this:

CClosure *func = (lua_assert(ttisCclosure(o)), &val_(ci->func).gc->cl.c)

The idea is that you force an assertion but only make an assignment of the right side of the parenthesis _expression_. The problem is "lua_assert", AFAIK, it's supposed to be replaced by an OS dependent version (Lua defines it void), which in many cases is a macro that looks like this:

#define OS_ASSERT do { /*STUFF*/ } while(0)

This way, when the OS specific assert is put in there you're left with something like this:

CClosure *func = (do { /*STUFF*/ } while(0), &val_(ci->func).gc->cl.c)

And that's not valid C. The left side must be an _expression_ but "do {}while()" is an statement, it rises an error and the code fails to compile.

I guess this should be managed another way?

Regards,
Javier