The semantics of luaL_checkudata() change between 5.0 and 5.1 (the later triggers an error).

make sure isXxx() functions do not trigger an error, we want them to return not to pop the stack back to the lua caller.


svn path=/trunk/; revision=17411
This commit is contained in:
Luis Ontanon 2006-02-25 12:54:25 +00:00
parent fbf8c0b820
commit 27e2c87833
3 changed files with 13 additions and 11 deletions

View File

@ -163,7 +163,13 @@ C* push##C(lua_State* L, C v) { \
return p; \
}\
gboolean is##C(lua_State* L,int i) { \
return (gboolean)(lua_isuserdata(L,i) && luaL_checkudata(L,3,#C)); \
void *p; \
if(lua_isuserdata(L,i)) return FALSE; \
p = lua_touserdata(L, i); \
lua_getfield(L, LUA_REGISTRYINDEX, #C); \
if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
lua_pop(L, 2); \
return p ? TRUE : FALSE; \
} \
C shift##C(lua_State* L,int i) { \
C* p; \

View File

@ -203,12 +203,9 @@ ELUA_CONSTRUCTOR Dumper_new(lua_State* L) {
ELUA_METHOD Dumper_close(lua_State* L) {
/* Closes a dumper */
Dumper* dp;
Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
int err;
luaL_checktype(L,1,LUA_TUSERDATA);
dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
if (! *dp)
ELUA_ERROR(Dumper_close,"Cannot operate on a closed dumper");
@ -350,13 +347,11 @@ ELUA_METHOD Dumper_dump_current(lua_State* L) {
}
static int Dumper__gc(lua_State* L) {
Dumper* dp;
Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
int err;
/* If we are Garbage Collected it means the Dumper is no longer usable. Close it */
luaL_checktype(L,1,LUA_TUSERDATA);
dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
if (! *dp)
return 0; /* already closed, nothing to do! */

View File

@ -289,10 +289,11 @@ static int ProtoItem_add_subtree(lua_State *L) {
ProtoItem item = checkProtoItem(L,1);
if (item) {
SubTree* ett = luaL_checkudata(L,2,"SubTree");
SubTree* ett;;
ProtoTree tree;
if (ett && *ett) {
if (isSubTree(L,2)) {
ett = luaL_checkudata(L,2,"SubTree");
tree = proto_item_add_subtree(item,**ett);
} else {
tree = proto_item_add_subtree(item,lua_ett);