aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-11-10 16:05:36 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-11-10 16:05:36 -0200
commitc97aa9485caf253eceebc00cf08cfa8b179fe35e (patch)
treeb54254b30e4354f4fdad5264cfd4e7baa9e40ab5
parente885b91326986f1b5a341e9ff1444c4f46c6241a (diff)
downloadlua-c97aa9485caf253eceebc00cf08cfa8b179fe35e.tar.gz
lua-c97aa9485caf253eceebc00cf08cfa8b179fe35e.tar.bz2
lua-c97aa9485caf253eceebc00cf08cfa8b179fe35e.zip
new function 'luaL_setmetatable'
-rw-r--r--lauxlib.c8
-rw-r--r--lauxlib.h3
-rw-r--r--liolib.c5
-rw-r--r--loadlib.c5
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 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.225 2010/11/09 11:04:15 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.226 2010/11/10 17:38:10 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -224,6 +224,12 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
224} 224}
225 225
226 226
227LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
228 luaL_getmetatable(L, tname);
229 lua_setmetatable(L, -2);
230}
231
232
227LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { 233LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
228 void *p = lua_touserdata(L, ud); 234 void *p = lua_touserdata(L, ud);
229 if (p != NULL) { /* value is a userdata? */ 235 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 @@
1/* 1/*
2** $Id: lauxlib.h,v 1.109 2010/10/25 20:31:11 roberto Exp roberto $ 2** $Id: lauxlib.h,v 1.110 2010/11/10 17:38:10 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -52,6 +52,7 @@ LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t);
52LUALIB_API void (luaL_checkany) (lua_State *L, int narg); 52LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
53 53
54LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 54LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
55LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
55LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); 56LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
56LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 57LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
57 58
diff --git a/liolib.c b/liolib.c
index 6786201a..4b15fd35 100644
--- a/liolib.c
+++ b/liolib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: liolib.c,v 2.93 2010/11/08 17:27:22 roberto Exp roberto $ 2** $Id: liolib.c,v 2.94 2010/11/09 16:57:49 roberto Exp roberto $
3** Standard I/O (and system) library 3** Standard I/O (and system) library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -114,8 +114,7 @@ static FILE *tofile (lua_State *L) {
114static FILE **newprefile (lua_State *L) { 114static FILE **newprefile (lua_State *L) {
115 FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *)); 115 FILE **pf = (FILE **)lua_newuserdata(L, sizeof(FILE *));
116 *pf = NULL; /* file handle is currently `closed' */ 116 *pf = NULL; /* file handle is currently `closed' */
117 luaL_getmetatable(L, LUA_FILEHANDLE); 117 luaL_setmetatable(L, LUA_FILEHANDLE);
118 lua_setmetatable(L, -2);
119 return pf; 118 return pf;
120} 119}
121 120
diff --git a/loadlib.c b/loadlib.c
index c9c1dff9..39e98907 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.91 2010/09/07 19:21:39 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.92 2010/10/29 14:35:09 roberto Exp roberto $
3** Dynamic library loader for Lua 3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5** 5**
@@ -239,8 +239,7 @@ static void **ll_register (lua_State *L, const char *path) {
239 lua_pop(L, 1); /* remove result from gettable */ 239 lua_pop(L, 1); /* remove result from gettable */
240 plib = (void **)lua_newuserdata(L, sizeof(const void *)); 240 plib = (void **)lua_newuserdata(L, sizeof(const void *));
241 *plib = NULL; 241 *plib = NULL;
242 luaL_getmetatable(L, "_LOADLIB"); 242 luaL_setmetatable(L, "_LOADLIB");
243 lua_setmetatable(L, -2);
244 lua_pushfstring(L, "%s%s", LIBPREFIX, path); 243 lua_pushfstring(L, "%s%s", LIBPREFIX, path);
245 lua_pushvalue(L, -2); 244 lua_pushvalue(L, -2);
246 lua_settable(L, LUA_REGISTRYINDEX); 245 lua_settable(L, LUA_REGISTRYINDEX);