new API function and built-in "lua_copytagmethods"

This commit is contained in:
Roberto Ierusalimschy 1997-12-11 15:21:11 -02:00
parent cdd261f332
commit 4daae2165d
3 changed files with 26 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lbuiltin.c,v 1.14 1997/12/01 20:30:44 roberto Exp roberto $ ** $Id: lbuiltin.c,v 1.15 1997/12/09 13:35:19 roberto Exp roberto $
** Built-in functions ** Built-in functions
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -299,6 +299,13 @@ static void newtag (void)
} }
static void copytagmethods (void)
{
lua_pushnumber(lua_copytagmethods(luaL_check_number(1),
luaL_check_number(2)));
}
static void rawgettable (void) static void rawgettable (void)
{ {
lua_Object t = luaL_nonnullarg(1); lua_Object t = luaL_nonnullarg(1);
@ -431,6 +438,7 @@ static struct luaL_reg int_funcs[] = {
{"call", luaI_call}, {"call", luaI_call},
{"collectgarbage", luaI_collectgarbage}, {"collectgarbage", luaI_collectgarbage},
{"dofile", internaldofile}, {"dofile", internaldofile},
{"copytagmethods", copytagmethods},
{"dostring", internaldostring}, {"dostring", internaldostring},
{"error", luaI_error}, {"error", luaI_error},
{"foreach", foreach}, {"foreach", foreach},

16
ltm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltm.c,v 1.9 1997/11/19 18:16:33 roberto Exp roberto $ ** $Id: ltm.c,v 1.10 1997/12/11 14:48:46 roberto Exp roberto $
** Tag methods ** Tag methods
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -46,7 +46,7 @@ static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */
}; };
static int validevent (lua_Type t, int e) static int validevent (int t, int e)
{ /* ORDER LUA_T */ { /* ORDER LUA_T */
return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; return (t < LUA_T_NIL) ? 1 : validevents[-t][e];
} }
@ -95,6 +95,18 @@ void luaT_realtag (int tag)
} }
int lua_copytagmethods (int tagto, int tagfrom)
{
int e;
checktag(tagto);
checktag(tagfrom);
for (e=0; e<IM_N; e++) {
if (validevent(tagto, e))
*luaT_getim(tagto, e) = *luaT_getim(tagfrom, e);
}
return tagto;
}
int luaT_efectivetag (TObject *o) int luaT_efectivetag (TObject *o)
{ {

4
lua.h
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lua.h,v 1.8 1997/12/01 20:31:25 roberto Exp roberto $ ** $Id: lua.h,v 1.9 1997/12/09 13:35:19 roberto Exp roberto $
** Lua - An Extensible Extension Language ** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br ** e-mail: lua@tecgraf.puc-rio.br
@ -64,6 +64,7 @@ lua_Object lua_gettagmethod (int tag, char *event);
lua_Object lua_seterrormethod (void); /* In: new method */ lua_Object lua_seterrormethod (void); /* In: new method */
int lua_newtag (void); int lua_newtag (void);
int lua_copytagmethods (int tagto, int tagfrom);
void lua_settag (int tag); /* In: object */ void lua_settag (int tag); /* In: object */
void lua_error (char *s); void lua_error (char *s);
@ -139,6 +140,7 @@ long lua_collectgarbage (long limit);
#define lua_pushcfunction(f) lua_pushCclosure(f, 0) #define lua_pushcfunction(f) lua_pushCclosure(f, 0)
#define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
/* ========================================================================== /* ==========================================================================