Skip to content

Commit 6ae112d

Browse files
committed
simplify luaC_register
1 parent b555ebb commit 6ae112d

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/luaclasslib.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,18 +472,16 @@ int register_c_class(lua_State *L, int idx) {
472472
int luaC_register(lua_State *L, int index) {
473473
if (lua_isuserdata(L, index)) return register_c_class(L, index);
474474
if (!luaC_isclass(L, index)) return 0;
475-
int top = lua_gettop(L), ret = 0;
476-
lua_pushvalue(L, index); // push class
477-
while (luaC_getname(L, -1)) { // get name
478-
lua_pushvalue(L, -2); // push class
479-
luaC_setreg(L); // register class
480-
if (!luaC_getparent(L, -1)) {
481-
ret = 1; // no more parents, operation successful
482-
break;
483-
}
484-
}
475+
int top = lua_gettop(L);
476+
lua_pushvalue(L, index); // push class
477+
do {
478+
if (luaC_getname(L, -1)) { // get name
479+
lua_pushvalue(L, -2); // push class
480+
luaC_setreg(L); // register class
481+
} else lua_pop(L, 1); // anonymous class, skip
482+
} while (luaC_getparent(L, -1));
485483
lua_settop(L, top);
486-
return ret;
484+
return 1;
487485
}
488486

489487
void luaC_unregister(lua_State *L, const char *name) {

0 commit comments

Comments
 (0)