diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-09 11:50:08 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-09 11:50:08 -0200 |
| commit | 80b3d28f4a9e518bf40b35f786199919180bfcd4 (patch) | |
| tree | e25a410ba61883244207e25b16a853991b417ebb | |
| parent | 69d97712ecfcd06aa4edb7374b262131210d0bbc (diff) | |
| download | lua-80b3d28f4a9e518bf40b35f786199919180bfcd4.tar.gz lua-80b3d28f4a9e518bf40b35f786199919180bfcd4.tar.bz2 lua-80b3d28f4a9e518bf40b35f786199919180bfcd4.zip | |
details (mainly error messages)
Diffstat (limited to '')
| -rw-r--r-- | lapi.c | 6 | ||||
| -rw-r--r-- | lauxlib.c | 17 | ||||
| -rw-r--r-- | lauxlib.h | 4 | ||||
| -rw-r--r-- | lbuiltin.c | 39 | ||||
| -rw-r--r-- | ldo.c | 5 | ||||
| -rw-r--r-- | lfunc.c | 10 | ||||
| -rw-r--r-- | lgc.c | 3 | ||||
| -rw-r--r-- | liolib.c | 8 | ||||
| -rw-r--r-- | llex.c | 8 | ||||
| -rw-r--r-- | lmathlib.c | 25 | ||||
| -rw-r--r-- | lstring.c | 6 | ||||
| -rw-r--r-- | lstrlib.c | 8 | ||||
| -rw-r--r-- | ltable.c | 4 | ||||
| -rw-r--r-- | lua.h | 8 | ||||
| -rw-r--r-- | lua.stx | 24 | ||||
| -rw-r--r-- | lvm.c | 6 |
16 files changed, 89 insertions, 92 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.10 1997/11/27 18:25:14 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.11 1997/11/28 16:56:05 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 | */ |
| @@ -142,7 +142,7 @@ lua_Object lua_rawgettable (void) | |||
| 142 | { | 142 | { |
| 143 | checkCparams(2); | 143 | checkCparams(2); |
| 144 | if (ttype(L->stack.top-2) != LUA_T_ARRAY) | 144 | if (ttype(L->stack.top-2) != LUA_T_ARRAY) |
| 145 | lua_error("indexed expression not a table in raw gettable"); | 145 | lua_error("indexed expression not a table in rawgettable"); |
| 146 | else { | 146 | else { |
| 147 | TObject *h = luaH_get(avalue(L->stack.top-2), L->stack.top-1); | 147 | TObject *h = luaH_get(avalue(L->stack.top-2), L->stack.top-1); |
| 148 | --L->stack.top; | 148 | --L->stack.top; |
| @@ -490,7 +490,7 @@ char *lua_getobjname (lua_Object o, char **name) | |||
| 490 | void lua_beginblock (void) | 490 | void lua_beginblock (void) |
| 491 | { | 491 | { |
| 492 | if (L->numCblocks >= MAX_C_BLOCKS) | 492 | if (L->numCblocks >= MAX_C_BLOCKS) |
| 493 | lua_error("`lua_beginblock': too many nested blocks"); | 493 | lua_error("too many nested blocks"); |
| 494 | L->Cblocks[L->numCblocks] = L->Cstack; | 494 | L->Cblocks[L->numCblocks] = L->Cstack; |
| 495 | L->numCblocks++; | 495 | L->numCblocks++; |
| 496 | } | 496 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.3 1997/11/04 15:27:53 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.4 1997/11/21 19:00:46 roberto Exp roberto $ |
| 3 | ** Auxiliar functions for building Lua libraries | 3 | ** Auxiliar functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -55,6 +55,21 @@ double luaL_opt_number (int numArg, double def) | |||
| 55 | { | 55 | { |
| 56 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : | 56 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : |
| 57 | luaL_check_number(numArg); | 57 | luaL_check_number(numArg); |
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | lua_Object luaL_tablearg (int arg) | ||
| 62 | { | ||
| 63 | lua_Object o = lua_getparam(arg); | ||
| 64 | luaL_arg_check(lua_istable(o), arg, "table expected"); | ||
| 65 | return o; | ||
| 66 | } | ||
| 67 | |||
| 68 | lua_Object luaL_functionarg (int arg) | ||
| 69 | { | ||
| 70 | lua_Object o = lua_getparam(arg); | ||
| 71 | luaL_arg_check(lua_isfunction(o), arg, "function expected"); | ||
| 72 | return o; | ||
| 58 | } | 73 | } |
| 59 | 74 | ||
| 60 | lua_Object luaL_nonnullarg (int numArg) | 75 | lua_Object luaL_nonnullarg (int numArg) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.h,v 1.2 1997/09/26 15:02:26 roberto Exp roberto $ | 2 | ** $Id: lauxlib.h,v 1.3 1997/11/21 19:00:46 roberto Exp roberto $ |
| 3 | ** Auxiliar functions for building Lua libraries | 3 | ** Auxiliar functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -23,6 +23,8 @@ char *luaL_check_string (int numArg); | |||
| 23 | char *luaL_opt_string (int numArg, char *def); | 23 | char *luaL_opt_string (int numArg, char *def); |
| 24 | double luaL_check_number (int numArg); | 24 | double luaL_check_number (int numArg); |
| 25 | double luaL_opt_number (int numArg, double def); | 25 | double luaL_opt_number (int numArg, double def); |
| 26 | lua_Object luaL_functionarg (int arg); | ||
| 27 | lua_Object luaL_tablearg (int arg); | ||
| 26 | lua_Object luaL_nonnullarg (int numArg); | 28 | lua_Object luaL_nonnullarg (int numArg); |
| 27 | void luaL_verror (char *fmt, ...); | 29 | void luaL_verror (char *fmt, ...); |
| 28 | 30 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbuiltin.c,v 1.13 1997/11/28 12:39:45 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.14 1997/12/01 20:30:44 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 | */ |
| @@ -23,21 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | static lua_Object tablearg (int arg) | ||
| 27 | { | ||
| 28 | lua_Object o = lua_getparam(arg); | ||
| 29 | luaL_arg_check(lua_istable(o), arg, "table expected"); | ||
| 30 | return o; | ||
| 31 | } | ||
| 32 | |||
| 33 | static lua_Object functionarg (int arg) | ||
| 34 | { | ||
| 35 | lua_Object o = lua_getparam(arg); | ||
| 36 | luaL_arg_check(lua_isfunction(o), arg, "function expected"); | ||
| 37 | return o; | ||
| 38 | } | ||
| 39 | |||
| 40 | |||
| 41 | static void pushstring (TaggedString *s) | 26 | static void pushstring (TaggedString *s) |
| 42 | { | 27 | { |
| 43 | TObject o; | 28 | TObject o; |
| @@ -71,7 +56,7 @@ static void nextvar (void) | |||
| 71 | 56 | ||
| 72 | static void foreachvar (void) | 57 | static void foreachvar (void) |
| 73 | { | 58 | { |
| 74 | TObject f = *luaA_Address(functionarg(1)); | 59 | TObject f = *luaA_Address(luaL_functionarg(1)); |
| 75 | GCnode *g; | 60 | GCnode *g; |
| 76 | StkId name = L->Cstack.base++; /* place to keep var name (to avoid GC) */ | 61 | StkId name = L->Cstack.base++; /* place to keep var name (to avoid GC) */ |
| 77 | ttype(L->stack.stack+name) = LUA_T_NIL; | 62 | ttype(L->stack.stack+name) = LUA_T_NIL; |
| @@ -95,7 +80,7 @@ static void foreachvar (void) | |||
| 95 | 80 | ||
| 96 | static void next (void) | 81 | static void next (void) |
| 97 | { | 82 | { |
| 98 | lua_Object o = tablearg(1); | 83 | lua_Object o = luaL_tablearg(1); |
| 99 | lua_Object r = luaL_nonnullarg(2); | 84 | lua_Object r = luaL_nonnullarg(2); |
| 100 | Node *n = luaH_next(luaA_Address(o), luaA_Address(r)); | 85 | Node *n = luaH_next(luaA_Address(o), luaA_Address(r)); |
| 101 | if (n) { | 86 | if (n) { |
| @@ -107,8 +92,8 @@ static void next (void) | |||
| 107 | 92 | ||
| 108 | static void foreach (void) | 93 | static void foreach (void) |
| 109 | { | 94 | { |
| 110 | TObject t = *luaA_Address(tablearg(1)); | 95 | TObject t = *luaA_Address(luaL_tablearg(1)); |
| 111 | TObject f = *luaA_Address(functionarg(2)); | 96 | TObject f = *luaA_Address(luaL_functionarg(2)); |
| 112 | int i; | 97 | int i; |
| 113 | for (i=0; i<avalue(&t)->nhash; i++) { | 98 | for (i=0; i<avalue(&t)->nhash; i++) { |
| 114 | Node *nd = &(avalue(&t)->node[i]); | 99 | Node *nd = &(avalue(&t)->node[i]); |
| @@ -165,7 +150,9 @@ static char *to_string (lua_Object obj) | |||
| 165 | } | 150 | } |
| 166 | case LUA_T_NIL: | 151 | case LUA_T_NIL: |
| 167 | return "nil"; | 152 | return "nil"; |
| 168 | default: return "<unknown object>"; | 153 | default: |
| 154 | lua_error("internal error"); | ||
| 155 | return NULL; /* to avoid warnings */ | ||
| 169 | } | 156 | } |
| 170 | } | 157 | } |
| 171 | 158 | ||
| @@ -203,9 +190,7 @@ static void lua_obj2number (void) | |||
| 203 | 190 | ||
| 204 | static void luaI_error (void) | 191 | static void luaI_error (void) |
| 205 | { | 192 | { |
| 206 | char *s = lua_getstring(lua_getparam(1)); | 193 | lua_error(lua_getstring(lua_getparam(1))); |
| 207 | if (s == NULL) s = "(no message)"; | ||
| 208 | lua_error(s); | ||
| 209 | } | 194 | } |
| 210 | 195 | ||
| 211 | 196 | ||
| @@ -262,7 +247,7 @@ static int getnarg (lua_Object table) | |||
| 262 | static void luaI_call (void) | 247 | static void luaI_call (void) |
| 263 | { | 248 | { |
| 264 | lua_Object f = luaL_nonnullarg(1); | 249 | lua_Object f = luaL_nonnullarg(1); |
| 265 | lua_Object arg = tablearg(2); | 250 | lua_Object arg = luaL_tablearg(2); |
| 266 | char *options = luaL_opt_string(3, ""); | 251 | char *options = luaL_opt_string(3, ""); |
| 267 | lua_Object err = lua_getparam(4); | 252 | lua_Object err = lua_getparam(4); |
| 268 | int narg = getnarg(arg); | 253 | int narg = getnarg(arg); |
| @@ -302,7 +287,7 @@ static void luaI_call (void) | |||
| 302 | 287 | ||
| 303 | static void settag (void) | 288 | static void settag (void) |
| 304 | { | 289 | { |
| 305 | lua_Object o = tablearg(1); | 290 | lua_Object o = luaL_tablearg(1); |
| 306 | lua_pushobject(o); | 291 | lua_pushobject(o); |
| 307 | lua_settag(luaL_check_number(2)); | 292 | lua_settag(luaL_check_number(2)); |
| 308 | } | 293 | } |
| @@ -354,7 +339,7 @@ static void gettagmethod (void) | |||
| 354 | 339 | ||
| 355 | static void seterrormethod (void) | 340 | static void seterrormethod (void) |
| 356 | { | 341 | { |
| 357 | lua_Object nf = functionarg(1); | 342 | lua_Object nf = luaL_functionarg(1); |
| 358 | lua_pushobject(nf); | 343 | lua_pushobject(nf); |
| 359 | lua_pushobject(lua_seterrormethod()); | 344 | lua_pushobject(lua_seterrormethod()); |
| 360 | } | 345 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 1.12 1997/11/26 20:44:52 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.13 1997/11/27 18:25:14 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -381,6 +381,7 @@ int lua_dofile (char *filename) | |||
| 381 | 381 | ||
| 382 | 382 | ||
| 383 | #define SIZE_PREF 20 /* size of string prefix to appear in error messages */ | 383 | #define SIZE_PREF 20 /* size of string prefix to appear in error messages */ |
| 384 | #define SSIZE_PREF "20" | ||
| 384 | 385 | ||
| 385 | 386 | ||
| 386 | int lua_dostring (char *str) | 387 | int lua_dostring (char *str) |
| @@ -390,7 +391,7 @@ int lua_dostring (char *str) | |||
| 390 | char *temp; | 391 | char *temp; |
| 391 | ZIO z; | 392 | ZIO z; |
| 392 | if (str == NULL) return 1; | 393 | if (str == NULL) return 1; |
| 393 | sprintf(buff, "(dostring) >> %.20s", str); | 394 | sprintf(buff, "(dostring) >> %." SSIZE_PREF "s", str); |
| 394 | temp = strchr(buff, '\n'); | 395 | temp = strchr(buff, '\n'); |
| 395 | if (temp) *temp = 0; /* end string after first line */ | 396 | if (temp) *temp = 0; /* end string after first line */ |
| 396 | luaZ_sopen(&z, str); | 397 | luaZ_sopen(&z, str); |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lfunc.c,v 1.5 1997/10/24 17:17:24 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.6 1997/11/19 17:29:23 roberto Exp roberto $ |
| 3 | ** Lua Funcion auxiliar | 3 | ** Auxiliar functions to manipulate prototypes and closures |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| @@ -11,8 +11,8 @@ | |||
| 11 | #include "lmem.h" | 11 | #include "lmem.h" |
| 12 | #include "lstate.h" | 12 | #include "lstate.h" |
| 13 | 13 | ||
| 14 | #define gcsizeproto(p) 5 | 14 | #define gcsizeproto(p) 5 /* approximate "weight" for a prototype */ |
| 15 | #define gcsizeclosure(c) 1 | 15 | #define gcsizeclosure(c) 1 /* approximate "weight" for a closure */ |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| @@ -83,7 +83,7 @@ void luaF_freeclosure (Closure *l) | |||
| 83 | 83 | ||
| 84 | 84 | ||
| 85 | /* | 85 | /* |
| 86 | ** Look for n-esim local variable at line "line" in function "func". | 86 | ** Look for n-th local variable at line "line" in function "func". |
| 87 | ** Returns NULL if not found. | 87 | ** Returns NULL if not found. |
| 88 | */ | 88 | */ |
| 89 | char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) | 89 | char *luaF_getlocalname (TProtoFunc *func, int local_number, int line) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lgc.c,v 1.9 1997/11/27 15:59:25 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.10 1997/12/01 20:31:25 roberto Exp roberto $ |
| 3 | ** Garbage Collector | 3 | ** Garbage Collector |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -268,7 +268,6 @@ long lua_collectgarbage (long limit) | |||
| 268 | luaF_freeclosure(freeclos); | 268 | luaF_freeclosure(freeclos); |
| 269 | luaM_clearbuffer(); | 269 | luaM_clearbuffer(); |
| 270 | recovered = recovered-L->nblocks; | 270 | recovered = recovered-L->nblocks; |
| 271 | /*printf("==total %ld coletados %ld\n", L->nblocks+recovered, recovered);*/ | ||
| 272 | L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; | 271 | L->GCthreshold = (limit == 0) ? 2*L->nblocks : L->nblocks+limit; |
| 273 | return recovered; | 272 | return recovered; |
| 274 | } | 273 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: liolib.c,v 1.7 1997/11/27 15:59:44 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 1.8 1997/11/28 12:40:37 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 | */ |
| @@ -28,7 +28,7 @@ | |||
| 28 | #define LC_MONETARY 0 | 28 | #define LC_MONETARY 0 |
| 29 | #define LC_NUMERIC 0 | 29 | #define LC_NUMERIC 0 |
| 30 | #define LC_TIME 0 | 30 | #define LC_TIME 0 |
| 31 | #define strerror(e) "O.S. is unable to define the error" | 31 | #define strerror(e) "(no error message provided by operating system)" |
| 32 | #endif | 32 | #endif |
| 33 | 33 | ||
| 34 | 34 | ||
| @@ -72,7 +72,7 @@ static int ishandler (lua_Object f) | |||
| 72 | { | 72 | { |
| 73 | if (lua_isuserdata(f)) { | 73 | if (lua_isuserdata(f)) { |
| 74 | if (lua_tag(f) == gettag(CLOSEDTAG)) | 74 | if (lua_tag(f) == gettag(CLOSEDTAG)) |
| 75 | lua_error("trying to access a closed file"); | 75 | lua_error("cannot access a closed file"); |
| 76 | return lua_tag(f) == gettag(IOTAG); | 76 | return lua_tag(f) == gettag(IOTAG); |
| 77 | } | 77 | } |
| 78 | else return 0; | 78 | else return 0; |
| @@ -82,7 +82,7 @@ static FILE *getfile (char *name) | |||
| 82 | { | 82 | { |
| 83 | lua_Object f = lua_getglobal(name); | 83 | lua_Object f = lua_getglobal(name); |
| 84 | if (!ishandler(f)) | 84 | if (!ishandler(f)) |
| 85 | luaL_verror("global variable %.50s is not a file handle", name); | 85 | luaL_verror("global variable `%.50s' is not a file handle", name); |
| 86 | return lua_getuserdata(f); | 86 | return lua_getuserdata(f); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llex.c,v 1.8 1997/11/21 19:00:46 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.9 1997/12/02 12:43:54 roberto Exp roberto $ |
| 3 | ** Lexical Analizer | 3 | ** Lexical Analizer |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -166,7 +166,7 @@ static void inclinenumber (LexState *LS) | |||
| 166 | /* go through */ | 166 | /* go through */ |
| 167 | case 5: /* if */ | 167 | case 5: /* if */ |
| 168 | if (LS->iflevel == MAX_IFS-1) | 168 | if (LS->iflevel == MAX_IFS-1) |
| 169 | luaY_syntaxerror("too many nested `$ifs'", "$if"); | 169 | luaY_syntaxerror("too many nested $ifs", "$if"); |
| 170 | readname(LS, buff); | 170 | readname(LS, buff); |
| 171 | LS->iflevel++; | 171 | LS->iflevel++; |
| 172 | LS->ifstate[LS->iflevel].elsepart = 0; | 172 | LS->ifstate[LS->iflevel].elsepart = 0; |
| @@ -181,7 +181,7 @@ static void inclinenumber (LexState *LS) | |||
| 181 | LS->ifstate[LS->iflevel].condition; | 181 | LS->ifstate[LS->iflevel].condition; |
| 182 | break; | 182 | break; |
| 183 | default: | 183 | default: |
| 184 | luaY_syntaxerror("invalid pragma", buff); | 184 | luaY_syntaxerror("unknown pragma", buff); |
| 185 | } | 185 | } |
| 186 | skipspace(LS); | 186 | skipspace(LS); |
| 187 | if (LS->current == '\n') /* pragma must end with a '\n' ... */ | 187 | if (LS->current == '\n') /* pragma must end with a '\n' ... */ |
| @@ -414,7 +414,7 @@ int luaY_lex (YYSTYPE *l) | |||
| 414 | case EOZ: | 414 | case EOZ: |
| 415 | save(LS, 0); | 415 | save(LS, 0); |
| 416 | if (LS->iflevel > 0) | 416 | if (LS->iflevel > 0) |
| 417 | luaY_error("missing $endif"); | 417 | luaY_syntaxerror("input ends inside a $if", ""); |
| 418 | return 0; | 418 | return 0; |
| 419 | 419 | ||
| 420 | default: | 420 | default: |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lmathlib.c,v 1.5 1997/11/19 18:16:33 roberto Exp roberto $ | 2 | ** $Id: lmathlib.c,v 1.6 1997/11/28 12:39:22 roberto Exp roberto $ |
| 3 | ** Lua standard mathematical library | 3 | ** Lua standard mathematical library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -12,28 +12,15 @@ | |||
| 12 | #include "lua.h" | 12 | #include "lua.h" |
| 13 | #include "lualib.h" | 13 | #include "lualib.h" |
| 14 | 14 | ||
| 15 | #ifndef PI | 15 | #ifdef M_PI |
| 16 | #define PI M_PI | ||
| 17 | #else | ||
| 16 | #define PI ((double)3.14159265358979323846) | 18 | #define PI ((double)3.14159265358979323846) |
| 17 | #endif | 19 | #endif |
| 18 | 20 | ||
| 19 | 21 | ||
| 20 | 22 | #define FROMRAD(a) ((a)*(180.0/PI)) | |
| 21 | #define FROMRAD(a) ((a)/torad()) | 23 | #define TORAD(a) ((a)*(PI/180.0)) |
| 22 | #define TORAD(a) ((a)*torad()) | ||
| 23 | |||
| 24 | |||
| 25 | static double torad (void) | ||
| 26 | { | ||
| 27 | char *s = luaL_opt_string(2, "d"); | ||
| 28 | switch (*s) { | ||
| 29 | case 'd' : return PI/180.0; | ||
| 30 | case 'r' : return (double)1.0; | ||
| 31 | case 'g' : return PI/50.0; | ||
| 32 | default: | ||
| 33 | luaL_arg_check(0, 2, "invalid mode"); | ||
| 34 | return 0; /* to avoid warnings */ | ||
| 35 | } | ||
| 36 | } | ||
| 37 | 24 | ||
| 38 | 25 | ||
| 39 | static void math_abs (void) | 26 | static void math_abs (void) |
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstring.c,v 1.6 1997/11/21 19:00:46 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 1.7 1997/12/01 20:31:25 roberto Exp roberto $ |
| 3 | ** String table (keep all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| @@ -17,7 +17,7 @@ | |||
| 17 | #define NUM_HASHS 61 | 17 | #define NUM_HASHS 61 |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | #define gcsizestring(l) (1+(l/64)) | 20 | #define gcsizestring(l) (1+(l/64)) /* "weight" for a string with length 'l' */ |
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lstrlib.c,v 1.1 1997/09/16 19:25:59 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.2 1997/11/26 18:53:45 roberto Exp roberto $ |
| 3 | ** Standard library for strings and pattern-matching | 3 | ** Standard library for strings and pattern-matching |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -283,7 +283,7 @@ static char *matchitem (char *s, char *p, int level, char **ep) | |||
| 283 | else if (*p == 'b') { /* balanced string */ | 283 | else if (*p == 'b') { /* balanced string */ |
| 284 | p++; | 284 | p++; |
| 285 | if (*p == 0 || *(p+1) == 0) | 285 | if (*p == 0 || *(p+1) == 0) |
| 286 | lua_error("bad balanced pattern specification"); | 286 | lua_error("unbalanced pattern"); |
| 287 | *ep = p+2; | 287 | *ep = p+2; |
| 288 | return matchbalance(s, *p, *(p+1)); | 288 | return matchbalance(s, *p, *(p+1)); |
| 289 | } | 289 | } |
| @@ -484,7 +484,7 @@ static void str_format (void) | |||
| 484 | arg++; | 484 | arg++; |
| 485 | strncpy(form+1, initf, strfrmt-initf+1); /* +1 to include convertion */ | 485 | strncpy(form+1, initf, strfrmt-initf+1); /* +1 to include convertion */ |
| 486 | form[strfrmt-initf+2] = 0; | 486 | form[strfrmt-initf+2] = 0; |
| 487 | buff = openspace(1000); /* to store the formated value */ | 487 | buff = openspace(1000); /* to store the formatted value */ |
| 488 | switch (*strfrmt++) { | 488 | switch (*strfrmt++) { |
| 489 | case 'q': | 489 | case 'q': |
| 490 | luaI_addquoted(luaL_check_string(arg)); | 490 | luaI_addquoted(luaL_check_string(arg)); |
| @@ -503,7 +503,7 @@ static void str_format (void) | |||
| 503 | sprintf(buff, form, luaL_check_number(arg)); | 503 | sprintf(buff, form, luaL_check_number(arg)); |
| 504 | break; | 504 | break; |
| 505 | default: /* also treat cases 'pnLlh' */ | 505 | default: /* also treat cases 'pnLlh' */ |
| 506 | lua_error("invalid format option in function `format'"); | 506 | lua_error("invalid option in `format'"); |
| 507 | } | 507 | } |
| 508 | lbuffer.size += strlen(buff); | 508 | lbuffer.size += strlen(buff); |
| 509 | } | 509 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltable.c,v 1.6 1997/11/19 17:29:23 roberto Exp roberto $ | 2 | ** $Id: ltable.c,v 1.7 1997/11/21 19:00:46 roberto Exp roberto $ |
| 3 | ** Lua tables (hash) | 3 | ** Lua tables (hash) |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -44,7 +44,7 @@ static long int hashindex (TObject *ref) | |||
| 44 | break; | 44 | break; |
| 45 | default: | 45 | default: |
| 46 | lua_error("unexpected type to index table"); | 46 | lua_error("unexpected type to index table"); |
| 47 | h = 0; /* UNREACHEABLE */ | 47 | h = 0; /* to avoid warnings */ |
| 48 | } | 48 | } |
| 49 | return (h >= 0 ? h : -(h+1)); | 49 | return (h >= 0 ? h : -(h+1)); |
| 50 | } | 50 | } |
| @@ -1,13 +1,15 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.h,v 1.7 1997/11/27 18:25:14 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.8 1997/12/01 20:31:25 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 |
| 6 | ** www: http://www.tecgraf.puc-rio.br/lua/ | ||
| 6 | */ | 7 | */ |
| 7 | 8 | ||
| 8 | /********************************************************************* | 9 | /********************************************************************* |
| 9 | * Copyright © 1994-1996 TeCGraf, PUC-Rio. Written by Waldemar Ce | 10 | * Copyright © 1994-1996 TeCGraf, PUC-Rio. |
| 10 | * les Filho, Roberto Ierusalimschy and Luiz Henrique de Figueiredo. | 11 | * Written by Waldemar Celes Filho, Roberto Ierusalimschy and |
| 12 | * Luiz Henrique de Figueiredo. | ||
| 11 | * All rights reserved. | 13 | * All rights reserved. |
| 12 | * | 14 | * |
| 13 | * Permission is hereby granted, without written agreement and with | 15 | * Permission is hereby granted, without written agreement and with |
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | /* | 2 | /* |
| 3 | ** $Id: lua.stx,v 1.19 1997/11/21 19:00:46 roberto Exp roberto $ | 3 | ** $Id: lua.stx,v 1.20 1997/12/02 12:43:54 roberto Exp roberto $ |
| 4 | ** Syntax analizer and code generator | 4 | ** Syntax analizer and code generator |
| 5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
| 6 | */ | 6 | */ |
| @@ -26,6 +26,10 @@ | |||
| 26 | int luaY_parse (void); | 26 | int luaY_parse (void); |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | #define AMES_LIM(x) #x | ||
| 30 | #define MES_LIM(x) "(limit=" AMES_LIM(x) ")" | ||
| 31 | |||
| 32 | |||
| 29 | /* size of a "normal" jump instruction: OpCode + 1 byte */ | 33 | /* size of a "normal" jump instruction: OpCode + 1 byte */ |
| 30 | #define JMPSIZE 2 | 34 | #define JMPSIZE 2 |
| 31 | 35 | ||
| @@ -43,6 +47,8 @@ int luaY_parse (void); | |||
| 43 | /* maximum number of upvalues */ | 47 | /* maximum number of upvalues */ |
| 44 | #define MAXUPVALUES 16 | 48 | #define MAXUPVALUES 16 |
| 45 | 49 | ||
| 50 | |||
| 51 | |||
| 46 | /* | 52 | /* |
| 47 | ** Variable descriptor: | 53 | ** Variable descriptor: |
| 48 | ** if 0<n<MINGLOBAL, represents local variable indexed by (n-1); | 54 | ** if 0<n<MINGLOBAL, represents local variable indexed by (n-1); |
| @@ -132,7 +138,7 @@ static void deltastack (int delta) | |||
| 132 | L->currState->stacksize += delta; | 138 | L->currState->stacksize += delta; |
| 133 | if (L->currState->stacksize > L->currState->maxstacksize) { | 139 | if (L->currState->stacksize > L->currState->maxstacksize) { |
| 134 | if (L->currState->stacksize > 255) | 140 | if (L->currState->stacksize > 255) |
| 135 | luaY_error("function/expression too complex (limit 256)"); | 141 | luaY_error("function/expression too complex"); |
| 136 | L->currState->maxstacksize = L->currState->stacksize; | 142 | L->currState->maxstacksize = L->currState->stacksize; |
| 137 | } | 143 | } |
| 138 | } | 144 | } |
| @@ -156,7 +162,7 @@ static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta) | |||
| 156 | L->currState->f->code[pc+2] = arg>>8; | 162 | L->currState->f->code[pc+2] = arg>>8; |
| 157 | return 3; | 163 | return 3; |
| 158 | } | 164 | } |
| 159 | else luaY_error("code too long (limit 64K)"); | 165 | else luaY_error("code too long " MES_LIM(64K)); |
| 160 | return 0; /* to avoid warnings */ | 166 | return 0; /* to avoid warnings */ |
| 161 | } | 167 | } |
| 162 | 168 | ||
| @@ -314,7 +320,7 @@ static void store_localvar (TaggedString *name, int n) | |||
| 314 | if (L->currState->nlocalvar+n < MAXLOCALS) | 320 | if (L->currState->nlocalvar+n < MAXLOCALS) |
| 315 | L->currState->localvar[L->currState->nlocalvar+n] = name; | 321 | L->currState->localvar[L->currState->nlocalvar+n] = name; |
| 316 | else | 322 | else |
| 317 | luaY_error("too many local variables (limit 32)"); | 323 | luaY_error("too many local variables " MES_LIM(MAXLOCALS)); |
| 318 | luaI_registerlocalvar(name, L->lexstate->linenumber); | 324 | luaI_registerlocalvar(name, L->lexstate->linenumber); |
| 319 | } | 325 | } |
| 320 | 326 | ||
| @@ -341,7 +347,7 @@ static vardesc var2store (vardesc var) | |||
| 341 | static void add_varbuffer (vardesc var, int n) | 347 | static void add_varbuffer (vardesc var, int n) |
| 342 | { | 348 | { |
| 343 | if (n >= MAXVAR) | 349 | if (n >= MAXVAR) |
| 344 | luaY_error("variable buffer overflow (limit 32)"); | 350 | luaY_error("variable buffer overflow " MES_LIM(MAXVAR)); |
| 345 | L->currState->varbuffer[n] = var2store(var); | 351 | L->currState->varbuffer[n] = var2store(var); |
| 346 | } | 352 | } |
| 347 | 353 | ||
| @@ -379,7 +385,7 @@ static int indexupvalue (TaggedString *n) | |||
| 379 | } | 385 | } |
| 380 | /* new one */ | 386 | /* new one */ |
| 381 | if (++(L->currState->nupvalues) > MAXUPVALUES) | 387 | if (++(L->currState->nupvalues) > MAXUPVALUES) |
| 382 | luaY_error("too many upvalues in a single function (limit 16)"); | 388 | luaY_error("too many upvalues in a single function " MES_LIM(MAXUPVALUES)); |
| 383 | L->currState->upvalues[i] = v; /* i = L->currState->nupvalues - 1 */ | 389 | L->currState->upvalues[i] = v; /* i = L->currState->nupvalues - 1 */ |
| 384 | return i; | 390 | return i; |
| 385 | } | 391 | } |
| @@ -493,7 +499,7 @@ static int lua_codestore (int i, int left) | |||
| 493 | } | 499 | } |
| 494 | else { /* indexed var with values in between*/ | 500 | else { /* indexed var with values in between*/ |
| 495 | code_oparg(SETTABLE, 0, left+i, -1); | 501 | code_oparg(SETTABLE, 0, left+i, -1); |
| 496 | return left+2; /* table/index are not poped, since they are not on top */ | 502 | return left+2; /* table/index are not popped, since they are not on top */ |
| 497 | } | 503 | } |
| 498 | } | 504 | } |
| 499 | 505 | ||
| @@ -580,7 +586,7 @@ static void init_state (TaggedString *filename) | |||
| 580 | static void init_func (void) | 586 | static void init_func (void) |
| 581 | { | 587 | { |
| 582 | if (L->currState-L->mainState >= MAXSTATES-1) | 588 | if (L->currState-L->mainState >= MAXSTATES-1) |
| 583 | luaY_error("too many nested functions (limit 6)"); | 589 | luaY_error("too many nested functions " MES_LIM(MAXSTATES)); |
| 584 | L->currState++; | 590 | L->currState++; |
| 585 | init_state(L->mainState->f->fileName); | 591 | init_state(L->mainState->f->fileName); |
| 586 | luaY_codedebugline(L->lexstate->linenumber); | 592 | luaY_codedebugline(L->lexstate->linenumber); |
| @@ -604,7 +610,7 @@ static TProtoFunc *close_func (void) | |||
| 604 | 610 | ||
| 605 | 611 | ||
| 606 | /* | 612 | /* |
| 607 | ** Parse LUA code. | 613 | ** Parse Lua code. |
| 608 | */ | 614 | */ |
| 609 | TProtoFunc *luaY_parser (ZIO *z, char *chunkname) | 615 | TProtoFunc *luaY_parser (ZIO *z, char *chunkname) |
| 610 | { | 616 | { |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.14 1997/11/19 17:29:23 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.15 1997/11/21 19:00:46 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -213,7 +213,7 @@ static void call_binTM (IMS event, char *msg) | |||
| 213 | 213 | ||
| 214 | static void call_arith (IMS event) | 214 | static void call_arith (IMS event) |
| 215 | { | 215 | { |
| 216 | call_binTM(event, "unexpected type at arithmetic operation"); | 216 | call_binTM(event, "unexpected type in arithmetic operation"); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | 219 | ||
| @@ -229,7 +229,7 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | |||
| 229 | else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) | 229 | else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) |
| 230 | result = strcoll(svalue(l), svalue(r)); | 230 | result = strcoll(svalue(l), svalue(r)); |
| 231 | else { | 231 | else { |
| 232 | call_binTM(op, "unexpected type at comparison"); | 232 | call_binTM(op, "unexpected type in comparison"); |
| 233 | return; | 233 | return; |
| 234 | } | 234 | } |
| 235 | S->top--; | 235 | S->top--; |
