new function 'luaL_setmetatable'

This commit is contained in:
Roberto Ierusalimschy
2010-11-10 16:05:36 -02:00
parent e885b91326
commit c97aa9485c
4 changed files with 13 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.225 2010/11/09 11:04:15 roberto Exp roberto $
** $Id: lauxlib.c,v 1.226 2010/11/10 17:38:10 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -224,6 +224,12 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
}
LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
luaL_getmetatable(L, tname);
lua_setmetatable(L, -2);
}
LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is a userdata? */