diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-11 15:21:11 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-11 15:21:11 -0200 |
| commit | 4daae2165d617e57ad1460471f8d902d38abac6e (patch) | |
| tree | 84eb55fa794a864ac48b528a617d5293502190ea | |
| parent | cdd261f332c112b86eddd7438b9a06e1231e3e4c (diff) | |
| download | lua-4daae2165d617e57ad1460471f8d902d38abac6e.tar.gz lua-4daae2165d617e57ad1460471f8d902d38abac6e.tar.bz2 lua-4daae2165d617e57ad1460471f8d902d38abac6e.zip | |
new API function and built-in "lua_copytagmethods"
| -rw-r--r-- | lbuiltin.c | 10 | ||||
| -rw-r--r-- | ltm.c | 16 | ||||
| -rw-r--r-- | lua.h | 4 |
3 files changed, 26 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuiltin.c,v 1.14 1997/12/01 20:30:44 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.15 1997/12/09 13:35:19 roberto Exp roberto $ |
| 3 | ** Built-in functions | 3 | ** Built-in functions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -299,6 +299,13 @@ static void newtag (void) | |||
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | 301 | ||
| 302 | static void copytagmethods (void) | ||
| 303 | { | ||
| 304 | lua_pushnumber(lua_copytagmethods(luaL_check_number(1), | ||
| 305 | luaL_check_number(2))); | ||
| 306 | } | ||
| 307 | |||
| 308 | |||
| 302 | static void rawgettable (void) | 309 | static void rawgettable (void) |
| 303 | { | 310 | { |
| 304 | lua_Object t = luaL_nonnullarg(1); | 311 | lua_Object t = luaL_nonnullarg(1); |
| @@ -431,6 +438,7 @@ static struct luaL_reg int_funcs[] = { | |||
| 431 | {"call", luaI_call}, | 438 | {"call", luaI_call}, |
| 432 | {"collectgarbage", luaI_collectgarbage}, | 439 | {"collectgarbage", luaI_collectgarbage}, |
| 433 | {"dofile", internaldofile}, | 440 | {"dofile", internaldofile}, |
| 441 | {"copytagmethods", copytagmethods}, | ||
| 434 | {"dostring", internaldostring}, | 442 | {"dostring", internaldostring}, |
| 435 | {"error", luaI_error}, | 443 | {"error", luaI_error}, |
| 436 | {"foreach", foreach}, | 444 | {"foreach", foreach}, |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.9 1997/11/19 18:16:33 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.10 1997/12/11 14:48:46 roberto Exp roberto $ |
| 3 | ** Tag methods | 3 | ** Tag methods |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -46,7 +46,7 @@ static char validevents[NUM_TAGS][IM_N] = { /* ORDER LUA_T, ORDER IM */ | |||
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | static int validevent (lua_Type t, int e) | 49 | static int validevent (int t, int e) |
| 50 | { /* ORDER LUA_T */ | 50 | { /* ORDER LUA_T */ |
| 51 | return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; | 51 | return (t < LUA_T_NIL) ? 1 : validevents[-t][e]; |
| 52 | } | 52 | } |
| @@ -95,6 +95,18 @@ void luaT_realtag (int tag) | |||
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | 97 | ||
| 98 | int lua_copytagmethods (int tagto, int tagfrom) | ||
| 99 | { | ||
| 100 | int e; | ||
| 101 | checktag(tagto); | ||
| 102 | checktag(tagfrom); | ||
| 103 | for (e=0; e<IM_N; e++) { | ||
| 104 | if (validevent(tagto, e)) | ||
| 105 | *luaT_getim(tagto, e) = *luaT_getim(tagfrom, e); | ||
| 106 | } | ||
| 107 | return tagto; | ||
| 108 | } | ||
| 109 | |||
| 98 | 110 | ||
| 99 | int luaT_efectivetag (TObject *o) | 111 | int luaT_efectivetag (TObject *o) |
| 100 | { | 112 | { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.8 1997/12/01 20:31:25 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.9 1997/12/09 13:35:19 roberto Exp roberto $ |
| 3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
| 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
| 5 | ** e-mail: lua@tecgraf.puc-rio.br | 5 | ** e-mail: lua@tecgraf.puc-rio.br |
| @@ -64,6 +64,7 @@ lua_Object lua_gettagmethod (int tag, char *event); | |||
| 64 | lua_Object lua_seterrormethod (void); /* In: new method */ | 64 | lua_Object lua_seterrormethod (void); /* In: new method */ |
| 65 | 65 | ||
| 66 | int lua_newtag (void); | 66 | int lua_newtag (void); |
| 67 | int lua_copytagmethods (int tagto, int tagfrom); | ||
| 67 | void lua_settag (int tag); /* In: object */ | 68 | void lua_settag (int tag); /* In: object */ |
| 68 | 69 | ||
| 69 | void lua_error (char *s); | 70 | void lua_error (char *s); |
| @@ -139,6 +140,7 @@ long lua_collectgarbage (long limit); | |||
| 139 | 140 | ||
| 140 | #define lua_pushcfunction(f) lua_pushCclosure(f, 0) | 141 | #define lua_pushcfunction(f) lua_pushCclosure(f, 0) |
| 141 | 142 | ||
| 143 | #define lua_clonetag(t) lua_copytagmethods(lua_newtag(), (t)) | ||
| 142 | 144 | ||
| 143 | 145 | ||
| 144 | /* ========================================================================== | 146 | /* ========================================================================== |
