diff options
Diffstat (limited to '')
| -rw-r--r-- | lapi.c | 30 | ||||
| -rw-r--r-- | lauxlib.c | 10 | ||||
| -rw-r--r-- | lbaselib.c | 25 | ||||
| -rw-r--r-- | liolib.c | 14 | ||||
| -rw-r--r-- | ltests.c | 8 | ||||
| -rw-r--r-- | ltm.c | 7 | ||||
| -rw-r--r-- | ltm.h | 4 | ||||
| -rw-r--r-- | lua.h | 51 |
8 files changed, 74 insertions, 75 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.146 2001/06/15 20:36:57 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.147 2001/06/26 13:20:45 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -134,22 +134,13 @@ LUA_API void lua_pushvalue (lua_State *L, int index) { | |||
| 134 | */ | 134 | */ |
| 135 | 135 | ||
| 136 | 136 | ||
| 137 | LUA_API int lua_type (lua_State *L, int index) { | 137 | LUA_API int lua_rawtag (lua_State *L, int index) { |
| 138 | StkId o = luaA_indexAcceptable(L, index); | 138 | StkId o = luaA_indexAcceptable(L, index); |
| 139 | return (o == NULL) ? LUA_TNONE : ttype(o); | 139 | return (o == NULL) ? LUA_TNONE : ttype(o); |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | 142 | ||
| 143 | LUA_API const l_char *lua_tag2name (lua_State *L, int tag) { | 143 | LUA_API const l_char *lua_type (lua_State *L, int index) { |
| 144 | const l_char *s; | ||
| 145 | lua_lock(L); | ||
| 146 | s = (tag == LUA_TNONE) ? l_s("no value") : basictypename(G(L), tag); | ||
| 147 | lua_unlock(L); | ||
| 148 | return s; | ||
| 149 | } | ||
| 150 | |||
| 151 | |||
| 152 | LUA_API const l_char *lua_xtypename (lua_State *L, int index) { | ||
| 153 | StkId o; | 144 | StkId o; |
| 154 | const l_char *type; | 145 | const l_char *type; |
| 155 | lua_lock(L); | 146 | lua_lock(L); |
| @@ -174,7 +165,7 @@ LUA_API int lua_isnumber (lua_State *L, int index) { | |||
| 174 | 165 | ||
| 175 | 166 | ||
| 176 | LUA_API int lua_isstring (lua_State *L, int index) { | 167 | LUA_API int lua_isstring (lua_State *L, int index) { |
| 177 | int t = lua_type(L, index); | 168 | int t = lua_rawtag(L, index); |
| 178 | return (t == LUA_TSTRING || t == LUA_TNUMBER); | 169 | return (t == LUA_TSTRING || t == LUA_TNUMBER); |
| 179 | } | 170 | } |
| 180 | 171 | ||
| @@ -587,7 +578,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { | |||
| 587 | ** miscellaneous functions | 578 | ** miscellaneous functions |
| 588 | */ | 579 | */ |
| 589 | 580 | ||
| 590 | LUA_API int lua_newxtype (lua_State *L, const l_char *name, int basictype) { | 581 | LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) { |
| 591 | int tag; | 582 | int tag; |
| 592 | lua_lock(L); | 583 | lua_lock(L); |
| 593 | if (basictype != LUA_TNONE && | 584 | if (basictype != LUA_TNONE && |
| @@ -618,6 +609,15 @@ LUA_API int lua_name2tag (lua_State *L, const l_char *name) { | |||
| 618 | } | 609 | } |
| 619 | 610 | ||
| 620 | 611 | ||
| 612 | LUA_API const l_char *lua_tag2name (lua_State *L, int tag) { | ||
| 613 | const l_char *s; | ||
| 614 | lua_lock(L); | ||
| 615 | s = (tag == LUA_TNONE) ? l_s("no value") : typenamebytag(G(L), tag); | ||
| 616 | lua_unlock(L); | ||
| 617 | return s; | ||
| 618 | } | ||
| 619 | |||
| 620 | |||
| 621 | LUA_API void lua_settag (lua_State *L, int tag) { | 621 | LUA_API void lua_settag (lua_State *L, int tag) { |
| 622 | int basictype; | 622 | int basictype; |
| 623 | lua_lock(L); | 623 | lua_lock(L); |
| @@ -627,7 +627,7 @@ LUA_API void lua_settag (lua_State *L, int tag) { | |||
| 627 | basictype = G(L)->TMtable[tag].basictype; | 627 | basictype = G(L)->TMtable[tag].basictype; |
| 628 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) | 628 | if (basictype != LUA_TNONE && basictype != ttype(L->top-1)) |
| 629 | luaO_verror(L, l_s("tag %d can only be used for type '%.20s'"), tag, | 629 | luaO_verror(L, l_s("tag %d can only be used for type '%.20s'"), tag, |
| 630 | basictypename(G(L), basictype)); | 630 | typenamebytag(G(L), basictype)); |
| 631 | switch (ttype(L->top-1)) { | 631 | switch (ttype(L->top-1)) { |
| 632 | case LUA_TTABLE: | 632 | case LUA_TTABLE: |
| 633 | hvalue(L->top-1)->htag = tag; | 633 | hvalue(L->top-1)->htag = tag; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.49 2001/03/26 14:31:49 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.50 2001/04/23 16:35:45 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 | */ |
| @@ -44,7 +44,7 @@ LUALIB_API void luaL_argerror (lua_State *L, int narg, const l_char *extramsg) { | |||
| 44 | 44 | ||
| 45 | static void type_error (lua_State *L, int narg, const l_char *tname) { | 45 | static void type_error (lua_State *L, int narg, const l_char *tname) { |
| 46 | l_char buff[80]; | 46 | l_char buff[80]; |
| 47 | sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_xtypename(L,narg)); | 47 | sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_type(L,narg)); |
| 48 | luaL_argerror(L, narg, buff); | 48 | luaL_argerror(L, narg, buff); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| @@ -61,20 +61,20 @@ LUALIB_API void luaL_checkstack (lua_State *L, int space, const l_char *mes) { | |||
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | LUALIB_API void luaL_checktype(lua_State *L, int narg, int t) { | 63 | LUALIB_API void luaL_checktype(lua_State *L, int narg, int t) { |
| 64 | if (lua_type(L, narg) != t) | 64 | if (lua_rawtag(L, narg) != t) |
| 65 | tag_error(L, narg, t); | 65 | tag_error(L, narg, t); |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | 68 | ||
| 69 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { | 69 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { |
| 70 | if (lua_type(L, narg) == LUA_TNONE) | 70 | if (lua_rawtag(L, narg) == LUA_TNONE) |
| 71 | luaL_argerror(L, narg, l_s("value expected")); | 71 | luaL_argerror(L, narg, l_s("value expected")); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | 74 | ||
| 75 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, | 75 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, |
| 76 | const l_char *name) { | 76 | const l_char *name) { |
| 77 | if (strcmp(lua_xtypename(L, narg), name) != 0) | 77 | if (strcmp(lua_type(L, narg), name) != 0) |
| 78 | type_error(L, narg, name); | 78 | type_error(L, narg, name); |
| 79 | return lua_touserdata(L, narg); | 79 | return lua_touserdata(L, narg); |
| 80 | } | 80 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.37 2001/06/06 18:00:19 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.38 2001/06/20 17:25:30 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -139,7 +139,7 @@ static int luaB_getglobal (lua_State *L) { | |||
| 139 | 139 | ||
| 140 | /* auxiliary function to get `tags' */ | 140 | /* auxiliary function to get `tags' */ |
| 141 | static int gettag (lua_State *L, int narg) { | 141 | static int gettag (lua_State *L, int narg) { |
| 142 | switch (lua_type(L, narg)) { | 142 | switch (lua_rawtag(L, narg)) { |
| 143 | case LUA_TNUMBER: | 143 | case LUA_TNUMBER: |
| 144 | return (int)lua_tonumber(L, narg); | 144 | return (int)lua_tonumber(L, narg); |
| 145 | case LUA_TSTRING: { | 145 | case LUA_TSTRING: { |
| @@ -162,7 +162,7 @@ static int luaB_tag (lua_State *L) { | |||
| 162 | return 1; | 162 | return 1; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | static int luaB_settag (lua_State *L) { | 165 | static int luaB_settype (lua_State *L) { |
| 166 | luaL_checktype(L, 1, LUA_TTABLE); | 166 | luaL_checktype(L, 1, LUA_TTABLE); |
| 167 | lua_pushvalue(L, 1); /* push table */ | 167 | lua_pushvalue(L, 1); /* push table */ |
| 168 | lua_settag(L, gettag(L, 2)); | 168 | lua_settag(L, gettag(L, 2)); |
| @@ -194,7 +194,7 @@ static int luaB_weakmode (lua_State *L) { | |||
| 194 | 194 | ||
| 195 | static int luaB_newtype (lua_State *L) { | 195 | static int luaB_newtype (lua_State *L) { |
| 196 | const l_char *name = luaL_opt_string(L, 1, NULL); | 196 | const l_char *name = luaL_opt_string(L, 1, NULL); |
| 197 | lua_pushnumber(L, lua_newxtype(L, name, LUA_TTABLE)); | 197 | lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE)); |
| 198 | return 1; | 198 | return 1; |
| 199 | } | 199 | } |
| 200 | 200 | ||
| @@ -267,14 +267,14 @@ static int luaB_collectgarbage (lua_State *L) { | |||
| 267 | 267 | ||
| 268 | static int luaB_type (lua_State *L) { | 268 | static int luaB_type (lua_State *L) { |
| 269 | luaL_checkany(L, 1); | 269 | luaL_checkany(L, 1); |
| 270 | lua_pushstring(L, lua_tag2name(L, lua_type(L, 1))); | 270 | lua_pushstring(L, lua_type(L, 1)); |
| 271 | return 1; | 271 | return 1; |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | 274 | ||
| 275 | static int luaB_xtype (lua_State *L) { | 275 | static int luaB_rawtype (lua_State *L) { |
| 276 | luaL_checkany(L, 1); | 276 | luaL_checkany(L, 1); |
| 277 | lua_pushstring(L, lua_xtypename(L, 1)); | 277 | lua_pushstring(L, lua_tag2name(L, lua_rawtag(L, 1))); |
| 278 | return 1; | 278 | return 1; |
| 279 | } | 279 | } |
| 280 | 280 | ||
| @@ -458,7 +458,7 @@ static int luaB_call (lua_State *L) { | |||
| 458 | 458 | ||
| 459 | static int luaB_tostring (lua_State *L) { | 459 | static int luaB_tostring (lua_State *L) { |
| 460 | l_char buff[64]; | 460 | l_char buff[64]; |
| 461 | switch (lua_type(L, 1)) { | 461 | switch (lua_rawtag(L, 1)) { |
| 462 | case LUA_TNUMBER: | 462 | case LUA_TNUMBER: |
| 463 | lua_pushstring(L, lua_tostring(L, 1)); | 463 | lua_pushstring(L, lua_tostring(L, 1)); |
| 464 | return 1; | 464 | return 1; |
| @@ -466,13 +466,13 @@ static int luaB_tostring (lua_State *L) { | |||
| 466 | lua_pushvalue(L, 1); | 466 | lua_pushvalue(L, 1); |
| 467 | return 1; | 467 | return 1; |
| 468 | case LUA_TTABLE: | 468 | case LUA_TTABLE: |
| 469 | sprintf(buff, l_s("%.40s: %p"), lua_xtypename(L, 1), lua_topointer(L, 1)); | 469 | sprintf(buff, l_s("%.40s: %p"), lua_type(L, 1), lua_topointer(L, 1)); |
| 470 | break; | 470 | break; |
| 471 | case LUA_TFUNCTION: | 471 | case LUA_TFUNCTION: |
| 472 | sprintf(buff, l_s("function: %p"), lua_topointer(L, 1)); | 472 | sprintf(buff, l_s("function: %p"), lua_topointer(L, 1)); |
| 473 | break; | 473 | break; |
| 474 | case LUA_TUSERDATA: { | 474 | case LUA_TUSERDATA: { |
| 475 | const l_char *t = lua_xtypename(L, 1); | 475 | const l_char *t = lua_type(L, 1); |
| 476 | if (strcmp(t, l_s("userdata")) == 0) | 476 | if (strcmp(t, l_s("userdata")) == 0) |
| 477 | sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), | 477 | sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1), |
| 478 | lua_touserdata(L, 1)); | 478 | lua_touserdata(L, 1)); |
| @@ -715,9 +715,11 @@ static const luaL_reg base_funcs[] = { | |||
| 715 | {l_s("rawset"), luaB_rawset}, | 715 | {l_s("rawset"), luaB_rawset}, |
| 716 | {l_s("rawgettable"), luaB_rawget}, /* for compatibility 3.2 */ | 716 | {l_s("rawgettable"), luaB_rawget}, /* for compatibility 3.2 */ |
| 717 | {l_s("rawsettable"), luaB_rawset}, /* for compatibility 3.2 */ | 717 | {l_s("rawsettable"), luaB_rawset}, /* for compatibility 3.2 */ |
| 718 | {l_s("rawtype"), luaB_rawtype}, | ||
| 718 | {l_s("require"), luaB_require}, | 719 | {l_s("require"), luaB_require}, |
| 719 | {l_s("setglobal"), luaB_setglobal}, | 720 | {l_s("setglobal"), luaB_setglobal}, |
| 720 | {l_s("settag"), luaB_settag}, | 721 | {l_s("settag"), luaB_settype}, /* for compatibility 4.0 */ |
| 722 | {l_s("settype"), luaB_settype}, | ||
| 721 | {l_s("settagmethod"), luaB_settagmethod}, | 723 | {l_s("settagmethod"), luaB_settagmethod}, |
| 722 | {l_s("tag"), luaB_tag}, | 724 | {l_s("tag"), luaB_tag}, |
| 723 | {l_s("tonumber"), luaB_tonumber}, | 725 | {l_s("tonumber"), luaB_tonumber}, |
| @@ -729,7 +731,6 @@ static const luaL_reg base_funcs[] = { | |||
| 729 | {l_s("tinsert"), luaB_tinsert}, | 731 | {l_s("tinsert"), luaB_tinsert}, |
| 730 | {l_s("tremove"), luaB_tremove}, | 732 | {l_s("tremove"), luaB_tremove}, |
| 731 | {l_s("unpack"), luaB_unpack}, | 733 | {l_s("unpack"), luaB_unpack}, |
| 732 | {l_s("xtype"), luaB_xtype}, | ||
| 733 | {l_s("weakmode"), luaB_weakmode} | 734 | {l_s("weakmode"), luaB_weakmode} |
| 734 | }; | 735 | }; |
| 735 | 736 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.117 2001/06/28 14:45:44 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.118 2001/07/12 14:59:14 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 | */ |
| @@ -77,14 +77,14 @@ static int pushresult (lua_State *L, int i) { | |||
| 77 | */ | 77 | */ |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | #define checkfile(L,f) (strcmp(lua_xtypename(L,(f)), FILEHANDLE) == 0) | 80 | #define checkfile(L,f) (strcmp(lua_type(L,(f)), FILEHANDLE) == 0) |
| 81 | 81 | ||
| 82 | 82 | ||
| 83 | static FILE *getopthandle (lua_State *L, int inout) { | 83 | static FILE *getopthandle (lua_State *L, int inout) { |
| 84 | FILE *p = (FILE *)lua_touserdata(L, 1); | 84 | FILE *p = (FILE *)lua_touserdata(L, 1); |
| 85 | if (p != NULL) { /* is it a userdata ? */ | 85 | if (p != NULL) { /* is it a userdata ? */ |
| 86 | if (!checkfile(L, 1)) { /* not a valid file handle? */ | 86 | if (!checkfile(L, 1)) { /* not a valid file handle? */ |
| 87 | if (strcmp(lua_xtypename(L, 1), CLOSEDFILEHANDLE) == 0) | 87 | if (strcmp(lua_type(L, 1), CLOSEDFILEHANDLE) == 0) |
| 88 | luaL_argerror(L, 1, l_s("file is closed")); | 88 | luaL_argerror(L, 1, l_s("file is closed")); |
| 89 | else | 89 | else |
| 90 | luaL_argerror(L, 1, l_s("(invalid value)")); | 90 | luaL_argerror(L, 1, l_s("(invalid value)")); |
| @@ -310,7 +310,7 @@ static int io_read (lua_State *L) { | |||
| 310 | luaL_checkstack(L, nargs+LUA_MINSTACK, l_s("too many arguments")); | 310 | luaL_checkstack(L, nargs+LUA_MINSTACK, l_s("too many arguments")); |
| 311 | success = 1; | 311 | success = 1; |
| 312 | for (n = 1; n<=nargs && success; n++) { | 312 | for (n = 1; n<=nargs && success; n++) { |
| 313 | if (lua_type(L, n) == LUA_TNUMBER) { | 313 | if (lua_rawtag(L, n) == LUA_TNUMBER) { |
| 314 | size_t l = (size_t)lua_tonumber(L, n); | 314 | size_t l = (size_t)lua_tonumber(L, n); |
| 315 | success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); | 315 | success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l); |
| 316 | } | 316 | } |
| @@ -362,7 +362,7 @@ static int io_write (lua_State *L) { | |||
| 362 | int arg; | 362 | int arg; |
| 363 | int status = 1; | 363 | int status = 1; |
| 364 | for (arg=1; arg<=nargs; arg++) { | 364 | for (arg=1; arg<=nargs; arg++) { |
| 365 | if (lua_type(L, arg) == LUA_TNUMBER) { | 365 | if (lua_rawtag(L, arg) == LUA_TNUMBER) { |
| 366 | /* optimization: could be done exactly as for strings */ | 366 | /* optimization: could be done exactly as for strings */ |
| 367 | status = status && | 367 | status = status && |
| 368 | fprintf(f, l_s(LUA_NUMBER_FMT), lua_tonumber(L, arg)) > 0; | 368 | fprintf(f, l_s(LUA_NUMBER_FMT), lua_tonumber(L, arg)) > 0; |
| @@ -686,8 +686,8 @@ static const luaL_reg iolib[] = { | |||
| 686 | 686 | ||
| 687 | 687 | ||
| 688 | LUALIB_API int lua_iolibopen (lua_State *L) { | 688 | LUALIB_API int lua_iolibopen (lua_State *L) { |
| 689 | int iotag = lua_newxtype(L, FILEHANDLE, LUA_TUSERDATA); | 689 | int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA); |
| 690 | lua_newxtype(L, CLOSEDFILEHANDLE, LUA_TUSERDATA); | 690 | lua_newtype(L, CLOSEDFILEHANDLE, LUA_TUSERDATA); |
| 691 | luaL_openl(L, iolib); | 691 | luaL_openl(L, iolib); |
| 692 | /* predefined file handles */ | 692 | /* predefined file handles */ |
| 693 | newfilewithname(L, stdin, basicfiles[INFILE]); | 693 | newfilewithname(L, stdin, basicfiles[INFILE]); |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltests.c,v 1.86 2001/06/28 19:58:57 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.87 2001/07/05 20:31:14 roberto Exp roberto $ |
| 3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -367,8 +367,8 @@ static int udataval (lua_State *L) { | |||
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | static int newtag (lua_State *L) { | 369 | static int newtag (lua_State *L) { |
| 370 | lua_pushnumber(L, lua_newxtype(L, lua_tostring(L, 1), | 370 | lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1), |
| 371 | (int)lua_tonumber(L, 2))); | 371 | (int)lua_tonumber(L, 2))); |
| 372 | return 1; | 372 | return 1; |
| 373 | } | 373 | } |
| 374 | 374 | ||
| @@ -619,7 +619,7 @@ static int testC (lua_State *L) { | |||
| 619 | lua_gettagmethod(L, tag, event); | 619 | lua_gettagmethod(L, tag, event); |
| 620 | } | 620 | } |
| 621 | else if EQ(l_s("type")) { | 621 | else if EQ(l_s("type")) { |
| 622 | lua_pushstring(L, lua_typename(L, lua_type(L, getnum))); | 622 | lua_pushstring(L, lua_type(L, getnum)); |
| 623 | } | 623 | } |
| 624 | else luaL_verror(L, l_s("unknown instruction %.30s"), buff); | 624 | else luaL_verror(L, l_s("unknown instruction %.30s"), buff); |
| 625 | } | 625 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.c,v 1.72 2001/06/06 18:00:19 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 1.73 2001/06/15 20:36:57 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 | */ |
| @@ -70,7 +70,8 @@ int luaT_validevent (int t, int e) { /* ORDER LUA_T */ | |||
| 70 | 70 | ||
| 71 | void luaT_init (lua_State *L) { | 71 | void luaT_init (lua_State *L) { |
| 72 | static const l_char *const typenames[NUM_TAGS] = { | 72 | static const l_char *const typenames[NUM_TAGS] = { |
| 73 | l_s("userdata"), l_s("nil"), l_s("number"), l_s("string"), l_s("table"), l_s("function") | 73 | l_s("userdata"), l_s("nil"), l_s("number"), l_s("string"), |
| 74 | l_s("table"), l_s("function") | ||
| 74 | }; | 75 | }; |
| 75 | int i; | 76 | int i; |
| 76 | for (i=0; i<NUM_TAGS; i++) | 77 | for (i=0; i<NUM_TAGS; i++) |
| @@ -177,7 +178,7 @@ LUA_API void lua_settagmethod (lua_State *L, int t, const l_char *event) { | |||
| 177 | checktag(L, t); | 178 | checktag(L, t); |
| 178 | if (!luaT_validevent(t, e)) | 179 | if (!luaT_validevent(t, e)) |
| 179 | luaO_verror(L, l_s("cannot change `%.20s' tag method for type `%.20s'%.20s"), | 180 | luaO_verror(L, l_s("cannot change `%.20s' tag method for type `%.20s'%.20s"), |
| 180 | luaT_eventname[e], basictypename(G(L), t), | 181 | luaT_eventname[e], typenamebytag(G(L), t), |
| 181 | (t == LUA_TTABLE || t == LUA_TUSERDATA) ? | 182 | (t == LUA_TTABLE || t == LUA_TUSERDATA) ? |
| 182 | l_s(" with default tag") : l_s("")); | 183 | l_s(" with default tag") : l_s("")); |
| 183 | switch (ttype(L->top - 1)) { | 184 | switch (ttype(L->top - 1)) { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltm.h,v 1.24 2001/02/23 17:17:25 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 1.25 2001/06/06 18:00:19 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 | */ |
| @@ -62,7 +62,7 @@ struct TM { | |||
| 62 | #define luaT_gettm(G,tag,event) (G->TMtable[tag].method[event]) | 62 | #define luaT_gettm(G,tag,event) (G->TMtable[tag].method[event]) |
| 63 | #define luaT_gettmbyObj(G,o,e) (luaT_gettm((G),luaT_tag(o),(e))) | 63 | #define luaT_gettmbyObj(G,o,e) (luaT_gettm((G),luaT_tag(o),(e))) |
| 64 | 64 | ||
| 65 | #define basictypename(G, t) getstr(G->TMtable[t].name) | 65 | #define typenamebytag(G, t) getstr(G->TMtable[t].name) |
| 66 | 66 | ||
| 67 | 67 | ||
| 68 | #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) | 68 | #define validtag(G,t) (NUM_TAGS <= (t) && (t) < G->ntag) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.99 2001/06/28 14:45:44 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.100 2001/07/05 19:32:42 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: info@lua.org | 5 | ** e-mail: info@lua.org |
| @@ -51,10 +51,16 @@ typedef struct lua_State lua_State; | |||
| 51 | 51 | ||
| 52 | typedef int (*lua_CFunction) (lua_State *L); | 52 | typedef int (*lua_CFunction) (lua_State *L); |
| 53 | 53 | ||
| 54 | |||
| 55 | /* | ||
| 56 | ** an invalid `tag' | ||
| 57 | */ | ||
| 58 | #define LUA_NOTAG (-1) | ||
| 59 | |||
| 54 | /* | 60 | /* |
| 55 | ** types returned by `lua_type' | 61 | ** tags for basic types |
| 56 | */ | 62 | */ |
| 57 | #define LUA_TNONE (-1) | 63 | #define LUA_TNONE LUA_NOTAG |
| 58 | 64 | ||
| 59 | #define LUA_TUSERDATA 0 | 65 | #define LUA_TUSERDATA 0 |
| 60 | #define LUA_TNIL 1 | 66 | #define LUA_TNIL 1 |
| @@ -63,11 +69,6 @@ typedef int (*lua_CFunction) (lua_State *L); | |||
| 63 | #define LUA_TTABLE 4 | 69 | #define LUA_TTABLE 4 |
| 64 | #define LUA_TFUNCTION 5 | 70 | #define LUA_TFUNCTION 5 |
| 65 | 71 | ||
| 66 | /* | ||
| 67 | ** an invalid `tag' | ||
| 68 | */ | ||
| 69 | #define LUA_NOTAG (-2) | ||
| 70 | |||
| 71 | 72 | ||
| 72 | /* minimum Lua stack available to a C function */ | 73 | /* minimum Lua stack available to a C function */ |
| 73 | #define LUA_MINSTACK 20 | 74 | #define LUA_MINSTACK 20 |
| @@ -122,13 +123,12 @@ LUA_API int lua_stackspace (lua_State *L); | |||
| 122 | ** access functions (stack -> C) | 123 | ** access functions (stack -> C) |
| 123 | */ | 124 | */ |
| 124 | 125 | ||
| 125 | LUA_API int lua_type (lua_State *L, int index); | 126 | LUA_API const lua_char *lua_type (lua_State *L, int index); |
| 126 | LUA_API const lua_char *lua_tag2name (lua_State *L, int tag); | ||
| 127 | LUA_API const lua_char *lua_xtypename (lua_State *L, int index); | ||
| 128 | LUA_API int lua_isnumber (lua_State *L, int index); | 127 | LUA_API int lua_isnumber (lua_State *L, int index); |
| 129 | LUA_API int lua_isstring (lua_State *L, int index); | 128 | LUA_API int lua_isstring (lua_State *L, int index); |
| 130 | LUA_API int lua_iscfunction (lua_State *L, int index); | 129 | LUA_API int lua_iscfunction (lua_State *L, int index); |
| 131 | LUA_API int lua_tag (lua_State *L, int index); | 130 | LUA_API int lua_tag (lua_State *L, int index); |
| 131 | LUA_API int lua_rawtag (lua_State *L, int index); | ||
| 132 | 132 | ||
| 133 | LUA_API int lua_equal (lua_State *L, int index1, int index2); | 133 | LUA_API int lua_equal (lua_State *L, int index1, int index2); |
| 134 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2); | 134 | LUA_API int lua_lessthan (lua_State *L, int index1, int index2); |
| @@ -201,11 +201,13 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold); | |||
| 201 | /* | 201 | /* |
| 202 | ** miscellaneous functions | 202 | ** miscellaneous functions |
| 203 | */ | 203 | */ |
| 204 | LUA_API int lua_newxtype (lua_State *L, const lua_char *name, int basictype); | 204 | LUA_API int lua_newtype (lua_State *L, const lua_char *name, int basictype); |
| 205 | LUA_API int lua_name2tag (lua_State *L, const lua_char *name); | ||
| 206 | LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); | 205 | LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom); |
| 207 | LUA_API void lua_settag (lua_State *L, int tag); | 206 | LUA_API void lua_settag (lua_State *L, int tag); |
| 208 | 207 | ||
| 208 | LUA_API int lua_name2tag (lua_State *L, const lua_char *name); | ||
| 209 | LUA_API const lua_char *lua_tag2name (lua_State *L, int tag); | ||
| 210 | |||
| 209 | LUA_API void lua_error (lua_State *L, const lua_char *s); | 211 | LUA_API void lua_error (lua_State *L, const lua_char *s); |
| 210 | 212 | ||
| 211 | LUA_API void lua_unref (lua_State *L, int ref); | 213 | LUA_API void lua_unref (lua_State *L, int ref); |
| @@ -219,14 +221,9 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size); | |||
| 219 | LUA_API void lua_newuserdatabox (lua_State *L, void *u); | 221 | LUA_API void lua_newuserdatabox (lua_State *L, void *u); |
| 220 | 222 | ||
| 221 | LUA_API void lua_setweakmode (lua_State *L, int mode); | 223 | LUA_API void lua_setweakmode (lua_State *L, int mode); |
| 222 | LUA_API int lua_getweakmode (lua_State *L, int index); | 224 | LUA_API int lua_getweakmode (lua_State *L, int index); |
| 223 | 225 | ||
| 224 | 226 | ||
| 225 | /* | ||
| 226 | ** deprecated function | ||
| 227 | */ | ||
| 228 | LUA_API void lua_pushusertag (lua_State *L, void *u, int tag); | ||
| 229 | |||
| 230 | 227 | ||
| 231 | /* | 228 | /* |
| 232 | ** =============================================================== | 229 | ** =============================================================== |
| @@ -242,11 +239,11 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag); | |||
| 242 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) | 239 | #define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0) |
| 243 | #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t)) | 240 | #define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t)) |
| 244 | 241 | ||
| 245 | #define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION) | 242 | #define lua_isfunction(L,n) (lua_rawtag(L,n) == LUA_TFUNCTION) |
| 246 | #define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE) | 243 | #define lua_istable(L,n) (lua_rawtag(L,n) == LUA_TTABLE) |
| 247 | #define lua_isuserdata(L,n) (lua_type(L,n) == LUA_TUSERDATA) | 244 | #define lua_isuserdata(L,n) (lua_rawtag(L,n) == LUA_TUSERDATA) |
| 248 | #define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL) | 245 | #define lua_isnil(L,n) (lua_rawtag(L,n) == LUA_TNIL) |
| 249 | #define lua_isnull(L,n) (lua_type(L,n) == LUA_TNONE) | 246 | #define lua_isnull(L,n) (lua_rawtag(L,n) == LUA_TNONE) |
| 250 | 247 | ||
| 251 | #define lua_pushliteral(L, s) lua_pushlstring(L, s, \ | 248 | #define lua_pushliteral(L, s) lua_pushlstring(L, s, \ |
| 252 | (sizeof(s)/sizeof(lua_char))-1) | 249 | (sizeof(s)/sizeof(lua_char))-1) |
| @@ -256,7 +253,7 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag); | |||
| 256 | /* | 253 | /* |
| 257 | ** compatibility macros | 254 | ** compatibility macros |
| 258 | */ | 255 | */ |
| 259 | #define lua_newtag(L) lua_newxtype(L, NULL, LUA_TNONE) | 256 | #define lua_newtag(L) lua_newtype(L, NULL, LUA_TNONE) |
| 260 | #define lua_typename lua_tag2name | 257 | #define lua_typename lua_tag2name |
| 261 | 258 | ||
| 262 | #endif | 259 | #endif |
| @@ -294,8 +291,8 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag); | |||
| 294 | /* | 291 | /* |
| 295 | ** formats for Lua numbers | 292 | ** formats for Lua numbers |
| 296 | */ | 293 | */ |
| 297 | #ifndef LUA_SCAN_NUMBER | 294 | #ifndef LUA_NUMBER_SCAN |
| 298 | #define LUA_SCAN_NUMBER "%lf" | 295 | #define LUA_NUMBER_SCAN "%lf" |
| 299 | #endif | 296 | #endif |
| 300 | #ifndef LUA_NUMBER_FMT | 297 | #ifndef LUA_NUMBER_FMT |
| 301 | #define LUA_NUMBER_FMT "%.16g" | 298 | #define LUA_NUMBER_FMT "%.16g" |
