From c97aa9485caf253eceebc00cf08cfa8b179fe35e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 10 Nov 2010 16:05:36 -0200 Subject: [PATCH] new function 'luaL_setmetatable' --- lauxlib.c | 8 +++++++- lauxlib.h | 3 ++- liolib.c | 5 ++--- loadlib.c | 5 ++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lauxlib.c b/lauxlib.c index 9dbf5519..b0fabe3f 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -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? */ diff --git a/lauxlib.h b/lauxlib.h index c39b033b..f4c32647 100644 --- a/lauxlib.h +++ b/lauxlib.h @@ -1,5 +1,5 @@ /* -** $Id: lauxlib.h,v 1.109 2010/10/25 20:31:11 roberto Exp roberto $ +** $Id: lauxlib.h,v 1.110 2010/11/10 17:38:10 roberto Exp roberto $ ** Auxiliary functions for building Lua libraries ** See Copyright Notice in lua.h */ @@ -52,6 +52,7 @@ LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); LUALIB_API void (luaL_checkany) (lua_State *L, int narg); LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); +LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); diff --git a/liolib.c b/liolib.c index 6786201a..4b15fd35 100644 --- a/liolib.c +++ b/liolib.c @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 2.93 2010/11/08 17:27:22 roberto Exp roberto $ +** $Id: liolib.c,v 2.94 2010/11/09 16:57:49 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -114,8 +114,7 @@ static FILE *tofile (lua_State *L) { static FILE **newprefile (lua_State *L) { FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); *pf = NULL; /* file handle is currently `closed' */ - luaL_getmetatable(L, LUA_FILEHANDLE); - lua_setmetatable(L, -2); + luaL_setmetatable(L, LUA_FILEHANDLE); return pf; } diff --git a/loadlib.c b/loadlib.c index c9c1dff9..39e98907 100644 --- a/loadlib.c +++ b/loadlib.c @@ -1,5 +1,5 @@ /* -** $Id: loadlib.c,v 1.91 2010/09/07 19:21:39 roberto Exp roberto $ +** $Id: loadlib.c,v 1.92 2010/10/29 14:35:09 roberto Exp roberto $ ** Dynamic library loader for Lua ** See Copyright Notice in lua.h ** @@ -239,8 +239,7 @@ static void **ll_register (lua_State *L, const char *path) { lua_pop(L, 1); /* remove result from gettable */ plib = (void **)lua_newuserdata(L, sizeof(const void *)); *plib = NULL; - luaL_getmetatable(L, "_LOADLIB"); - lua_setmetatable(L, -2); + luaL_setmetatable(L, "_LOADLIB"); lua_pushfstring(L, "%s%s", LIBPREFIX, path); lua_pushvalue(L, -2); lua_settable(L, LUA_REGISTRYINDEX);