diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-11-10 16:05:36 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-11-10 16:05:36 -0200 |
commit | c97aa9485caf253eceebc00cf08cfa8b179fe35e (patch) | |
tree | b54254b30e4354f4fdad5264cfd4e7baa9e40ab5 | |
parent | e885b91326986f1b5a341e9ff1444c4f46c6241a (diff) | |
download | lua-c97aa9485caf253eceebc00cf08cfa8b179fe35e.tar.gz lua-c97aa9485caf253eceebc00cf08cfa8b179fe35e.tar.bz2 lua-c97aa9485caf253eceebc00cf08cfa8b179fe35e.zip |
new function 'luaL_setmetatable'
-rw-r--r-- | lauxlib.c | 8 | ||||
-rw-r--r-- | lauxlib.h | 3 | ||||
-rw-r--r-- | liolib.c | 5 | ||||
-rw-r--r-- | loadlib.c | 5 |
4 files changed, 13 insertions, 8 deletions
@@ -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 | ||
227 | LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) { | ||
228 | luaL_getmetatable(L, tname); | ||
229 | lua_setmetatable(L, -2); | ||
230 | } | ||
231 | |||
232 | |||
227 | LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { | 233 | LUALIB_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? */ |
@@ -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); | |||
52 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); | 52 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); |
53 | 53 | ||
54 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); | 54 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); |
55 | LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); | ||
55 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); | 56 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); |
56 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); | 57 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); |
57 | 58 | ||
@@ -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) { | |||
114 | static FILE **newprefile (lua_State *L) { | 114 | static 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 | ||
@@ -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); |