mirror of
https://github.com/lua/lua
synced 2024-11-26 06:39:41 +03:00
new function 'luaL_setmetatable'
This commit is contained in:
parent
e885b91326
commit
c97aa9485c
@ -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? */
|
||||
|
@ -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);
|
||||
|
||||
|
5
liolib.c
5
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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user