Merge pull request #2659 from psychon/luaA_setfuncs
Migrate a bit away from luaL_register().
This commit is contained in:
commit
052f6fb89d
|
@ -131,7 +131,7 @@ luaA_openlib(lua_State *L, const char *name,
|
||||||
lua_pushvalue(L, -1); /* dup metatable 2 */
|
lua_pushvalue(L, -1); /* dup metatable 2 */
|
||||||
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable 1 */
|
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable 1 */
|
||||||
|
|
||||||
luaA_registerlib(L, NULL, meta); /* 1 */
|
luaA_setfuncs(L, meta); /* 1 */
|
||||||
luaA_registerlib(L, name, methods); /* 2 */
|
luaA_registerlib(L, name, methods); /* 2 */
|
||||||
lua_pushvalue(L, -1); /* dup self as metatable 3 */
|
lua_pushvalue(L, -1); /* dup self as metatable 3 */
|
||||||
lua_setmetatable(L, -2); /* set self as metatable 2 */
|
lua_setmetatable(L, -2); /* set self as metatable 2 */
|
||||||
|
@ -267,7 +267,7 @@ luaA_class_setup(lua_State *L, lua_class_t *class,
|
||||||
|
|
||||||
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable 1 */
|
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable 1 */
|
||||||
|
|
||||||
luaA_registerlib(L, NULL, meta); /* 1 */
|
luaA_setfuncs(L, meta); /* 1 */
|
||||||
luaA_registerlib(L, name, methods); /* 2 */
|
luaA_registerlib(L, name, methods); /* 2 */
|
||||||
lua_pushvalue(L, -1); /* dup self as metatable 3 */
|
lua_pushvalue(L, -1); /* dup self as metatable 3 */
|
||||||
lua_setmetatable(L, -2); /* set self as metatable 2 */
|
lua_setmetatable(L, -2); /* set self as metatable 2 */
|
||||||
|
|
16
luaa.h
16
luaa.h
|
@ -128,21 +128,27 @@ luaA_rawlen(lua_State *L, int idx)
|
||||||
static inline void
|
static inline void
|
||||||
luaA_registerlib(lua_State *L, const char *libname, const luaL_Reg *l)
|
luaA_registerlib(lua_State *L, const char *libname, const luaL_Reg *l)
|
||||||
{
|
{
|
||||||
|
assert(libname);
|
||||||
#if LUA_VERSION_NUM >= 502
|
#if LUA_VERSION_NUM >= 502
|
||||||
if (libname)
|
|
||||||
{
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
luaL_setfuncs(L, l, 0);
|
luaL_setfuncs(L, l, 0);
|
||||||
lua_pushvalue(L, -1);
|
lua_pushvalue(L, -1);
|
||||||
lua_setglobal(L, libname);
|
lua_setglobal(L, libname);
|
||||||
}
|
|
||||||
else
|
|
||||||
luaL_setfuncs(L, l, 0);
|
|
||||||
#else
|
#else
|
||||||
luaL_register(L, libname, l);
|
luaL_register(L, libname, l);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
luaA_setfuncs(lua_State *L, const luaL_Reg *l)
|
||||||
|
{
|
||||||
|
#if LUA_VERSION_NUM >= 502
|
||||||
|
luaL_setfuncs(L, l, 0);
|
||||||
|
#else
|
||||||
|
luaL_register(L, NULL, l);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
luaA_checkboolean(lua_State *L, int n)
|
luaA_checkboolean(lua_State *L, int n)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue