@@ -229,10 +229,12 @@ luaA_class_gc(lua_State *L)
229229 * \param newindex_miss_property Function to call when an object of this class
230230 * receive a __newindex request on an unknown property.
231231 * \param methods The methods to set on the class table.
232+ * \param n_methods The number of methods.
232233 * \param meta The meta-methods to set on the class objects.
234+ * \param n_meta The number of meta-methods.
233235 */
234236void
235- luaA_class_setup (lua_State * L , lua_class_t * class ,
237+ luaA_class_setupx (lua_State * L , lua_class_t * class ,
236238 const char * name ,
237239 lua_class_t * parent ,
238240 lua_class_allocator_t allocator ,
@@ -241,10 +243,12 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
241243 lua_class_propfunc_t index_miss_property ,
242244 lua_class_propfunc_t newindex_miss_property ,
243245 const struct luaL_Reg methods [],
244- const struct luaL_Reg meta [])
246+ int n_methods ,
247+ const struct luaL_Reg meta [],
248+ int n_meta )
245249{
246250 /* Create the object metatable */
247- lua_newtable ( L );
251+ lua_createtable ( L , 0 , n_meta + 2 ); /* The +2 is for __gc and __index. */
248252 /* Register it with class pointer as key in the registry
249253 * class-pointer -> metatable */
250254 lua_pushlightuserdata (L , class );
@@ -266,7 +270,11 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
266270 lua_setfield (L , -2 , "__index" ); /* metatable.__index = metatable 1 */
267271
268272 luaA_setfuncs (L , meta ); /* 1 */
269- luaA_registerlib (L , name , methods ); /* 2 */
273+ lua_createtable (L , 0 , n_methods ); /* 2 */
274+ luaA_setfuncs (L , methods );
275+ lua_pushvalue (L , -1 );
276+ lua_setglobal (L , name );
277+
270278 lua_pushvalue (L , -1 ); /* dup self as metatable 3 */
271279 lua_setmetatable (L , -2 ); /* set self as metatable 2 */
272280 lua_pop (L , 2 );
0 commit comments