commit 4daae2165d617e57ad1460471f8d902d38abac6e
parent cdd261f332c112b86eddd7438b9a06e1231e3e4c
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 11 Dec 1997 15:20:50 -0200
new API function and built-in "lua_copytagmethods"
Diffstat:
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/lbuiltin.c b/lbuiltin.c
@@ -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
** 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)
{
lua_Object t = luaL_nonnullarg(1);
@@ -431,6 +438,7 @@ static struct luaL_reg int_funcs[] = {
{"call", luaI_call},
{"collectgarbage", luaI_collectgarbage},
{"dofile", internaldofile},
+ {"copytagmethods", copytagmethods},
{"dostring", internaldostring},
{"error", luaI_error},
{"foreach", foreach},
diff --git a/ltm.c b/ltm.c
@@ -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
** 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 */
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)
{
diff --git a/lua.h b/lua.h
@@ -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
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** 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 */
int lua_newtag (void);
+int lua_copytagmethods (int tagto, int tagfrom);
void lua_settag (int tag); /* In: object */
void lua_error (char *s);
@@ -139,6 +140,7 @@ long lua_collectgarbage (long limit);
#define lua_pushcfunction(f) lua_pushCclosure(f, 0)
+#define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t))
/* ==========================================================================