new constant LUA_NOOBJECT.

'lua_error' never returns
This commit is contained in:
Roberto Ierusalimschy 1994-12-16 13:53:57 -02:00
parent 891cab8a31
commit fad57bfa00
3 changed files with 74 additions and 74 deletions

18
iolib.c
View File

@ -3,7 +3,7 @@
** Input/output library to LUA ** Input/output library to LUA
*/ */
char *rcs_iolib="$Id: iolib.c,v 1.16 1994/11/16 17:38:08 roberto Stab roberto $"; char *rcs_iolib="$Id: iolib.c,v 1.17 1994/12/13 15:55:41 roberto Exp roberto $";
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
@ -29,7 +29,7 @@ static FILE *in=stdin, *out=stdout;
static void io_readfrom (void) static void io_readfrom (void)
{ {
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) /* restore standart input */ if (o == LUA_NOOBJECT) /* restore standart input */
{ {
if (in != stdin) if (in != stdin)
{ {
@ -74,7 +74,7 @@ static void io_readfrom (void)
static void io_writeto (void) static void io_writeto (void)
{ {
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) /* restore standart output */ if (o == LUA_NOOBJECT) /* restore standart output */
{ {
if (out != stdout) if (out != stdout)
{ {
@ -120,7 +120,7 @@ static void io_writeto (void)
static void io_appendto (void) static void io_appendto (void)
{ {
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) /* restore standart output */ if (o == LUA_NOOBJECT) /* restore standart output */
{ {
if (out != stdout) if (out != stdout)
{ {
@ -177,7 +177,7 @@ static void io_appendto (void)
static void io_read (void) static void io_read (void)
{ {
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL || !lua_isstring(o)) /* free format */ if (!lua_isstring(o)) /* free format */
{ {
int c; int c;
char s[256]; char s[256];
@ -442,12 +442,12 @@ static void io_write (void)
{ {
lua_Object o1 = lua_getparam (1); lua_Object o1 = lua_getparam (1);
lua_Object o2 = lua_getparam (2); lua_Object o2 = lua_getparam (2);
if (o1 == NULL) /* new line */ if (o1 == LUA_NOOBJECT) /* new line */
{ {
fprintf (out, "\n"); fprintf (out, "\n");
lua_pushnumber(1); lua_pushnumber(1);
} }
else if (o2 == NULL) /* free format */ else if (o2 == LUA_NOOBJECT) /* free format */
{ {
int status=0; int status=0;
if (lua_isnumber(o1)) if (lua_isnumber(o1))
@ -475,7 +475,7 @@ static void io_write (void)
static void io_execute (void) static void io_execute (void)
{ {
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL || !lua_isstring (o)) if (!lua_isstring (o))
{ {
lua_error ("incorrect argument to function 'execute`"); lua_error ("incorrect argument to function 'execute`");
lua_pushnumber (0); lua_pushnumber (0);
@ -495,7 +495,7 @@ static void io_execute (void)
static void io_remove (void) static void io_remove (void)
{ {
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL || !lua_isstring (o)) if (!lua_isstring (o))
{ {
lua_error ("incorrect argument to function 'execute`"); lua_error ("incorrect argument to function 'execute`");
lua_pushnumber (0); lua_pushnumber (0);

114
mathlib.c
View File

@ -3,7 +3,7 @@
** Mathematics library to LUA ** Mathematics library to LUA
*/ */
char *rcs_mathlib="$Id: mathlib.c,v 1.5 1994/11/17 19:43:34 roberto Exp roberto $"; char *rcs_mathlib="$Id: mathlib.c,v 1.6 1994/11/18 19:46:21 roberto Stab roberto $";
#include <stdio.h> /* NULL */ #include <stdio.h> /* NULL */
#include <math.h> #include <math.h>
@ -19,10 +19,10 @@ static void math_abs (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `abs'"); return; } lua_error ("too few arguments to function `abs'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `abs'"); return; } lua_error ("incorrect arguments to function `abs'");
d = lua_getnumber(o); d = lua_getnumber(o);
if (d < 0) d = -d; if (d < 0) d = -d;
lua_pushnumber (d); lua_pushnumber (d);
@ -33,10 +33,10 @@ static void math_sin (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `sin'"); return; } lua_error ("too few arguments to function `sin'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `sin'"); return; } lua_error ("incorrect arguments to function `sin'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (sin(TORAD(d))); lua_pushnumber (sin(TORAD(d)));
} }
@ -47,10 +47,10 @@ static void math_cos (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `cos'"); return; } lua_error ("too few arguments to function `cos'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `cos'"); return; } lua_error ("incorrect arguments to function `cos'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (cos(TORAD(d))); lua_pushnumber (cos(TORAD(d)));
} }
@ -61,10 +61,10 @@ static void math_tan (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `tan'"); return; } lua_error ("too few arguments to function `tan'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `tan'"); return; } lua_error ("incorrect arguments to function `tan'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (tan(TORAD(d))); lua_pushnumber (tan(TORAD(d)));
} }
@ -74,10 +74,10 @@ static void math_asin (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `asin'"); return; } lua_error ("too few arguments to function `asin'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `asin'"); return; } lua_error ("incorrect arguments to function `asin'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (TODEGREE(asin(d))); lua_pushnumber (TODEGREE(asin(d)));
} }
@ -87,10 +87,10 @@ static void math_acos (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `acos'"); return; } lua_error ("too few arguments to function `acos'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `acos'"); return; } lua_error ("incorrect arguments to function `acos'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (TODEGREE(acos(d))); lua_pushnumber (TODEGREE(acos(d)));
} }
@ -101,10 +101,10 @@ static void math_atan (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `atan'"); return; } lua_error ("too few arguments to function `atan'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `atan'"); return; } lua_error ("incorrect arguments to function `atan'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (TODEGREE(atan(d))); lua_pushnumber (TODEGREE(atan(d)));
} }
@ -114,10 +114,10 @@ static void math_ceil (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `ceil'"); return; } lua_error ("too few arguments to function `ceil'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `ceil'"); return; } lua_error ("incorrect arguments to function `ceil'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (ceil(d)); lua_pushnumber (ceil(d));
} }
@ -127,10 +127,10 @@ static void math_floor (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `floor'"); return; } lua_error ("too few arguments to function `floor'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `floor'"); return; } lua_error ("incorrect arguments to function `floor'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (floor(d)); lua_pushnumber (floor(d));
} }
@ -141,7 +141,7 @@ static void math_mod (void)
lua_Object o1 = lua_getparam (1); lua_Object o1 = lua_getparam (1);
lua_Object o2 = lua_getparam (2); lua_Object o2 = lua_getparam (2);
if (!lua_isnumber(o1) || !lua_isnumber(o2)) if (!lua_isnumber(o1) || !lua_isnumber(o2))
{ lua_error ("incorrect arguments to function `mod'"); return; } lua_error ("incorrect arguments to function `mod'");
d1 = (int) lua_getnumber(o1); d1 = (int) lua_getnumber(o1);
d2 = (int) lua_getnumber(o2); d2 = (int) lua_getnumber(o2);
lua_pushnumber (d1%d2); lua_pushnumber (d1%d2);
@ -152,10 +152,10 @@ static void math_sqrt (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `sqrt'"); return; } lua_error ("too few arguments to function `sqrt'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `sqrt'"); return; } lua_error ("incorrect arguments to function `sqrt'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (sqrt(d)); lua_pushnumber (sqrt(d));
} }
@ -188,15 +188,15 @@ static void math_min (void)
int i=1; int i=1;
double d, dmin; double d, dmin;
lua_Object o; lua_Object o;
if ((o = lua_getparam(i++)) == NULL) if ((o = lua_getparam(i++)) == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `min'"); return; } lua_error ("too few arguments to function `min'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `min'"); return; } lua_error ("incorrect arguments to function `min'");
dmin = lua_getnumber (o); dmin = lua_getnumber (o);
while ((o = lua_getparam(i++)) != NULL) while ((o = lua_getparam(i++)) != LUA_NOOBJECT)
{ {
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `min'"); return; } lua_error ("incorrect arguments to function `min'");
d = lua_getnumber (o); d = lua_getnumber (o);
if (d < dmin) dmin = d; if (d < dmin) dmin = d;
} }
@ -209,15 +209,15 @@ static void math_max (void)
int i=1; int i=1;
double d, dmax; double d, dmax;
lua_Object o; lua_Object o;
if ((o = lua_getparam(i++)) == NULL) if ((o = lua_getparam(i++)) == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `max'"); return; } lua_error ("too few arguments to function `max'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `max'"); return; } lua_error ("incorrect arguments to function `max'");
dmax = lua_getnumber (o); dmax = lua_getnumber (o);
while ((o = lua_getparam(i++)) != NULL) while ((o = lua_getparam(i++)) != LUA_NOOBJECT)
{ {
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `max'"); return; } lua_error ("incorrect arguments to function `max'");
d = lua_getnumber (o); d = lua_getnumber (o);
if (d > dmax) dmax = d; if (d > dmax) dmax = d;
} }
@ -229,10 +229,10 @@ static void math_log (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `log'"); return; } lua_error ("too few arguments to function `log'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `log'"); return; } lua_error ("incorrect arguments to function `log'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (log(d)); lua_pushnumber (log(d));
} }
@ -242,10 +242,10 @@ static void math_log10 (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `log10'"); return; } lua_error ("too few arguments to function `log10'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `log10'"); return; } lua_error ("incorrect arguments to function `log10'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (log10(d)); lua_pushnumber (log10(d));
} }
@ -255,10 +255,10 @@ static void math_exp (void)
{ {
double d; double d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `exp'"); return; } lua_error ("too few arguments to function `exp'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `exp'"); return; } lua_error ("incorrect arguments to function `exp'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (exp(d)); lua_pushnumber (exp(d));
} }
@ -267,10 +267,10 @@ static void math_deg (void)
{ {
float d; float d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `deg'"); return; } lua_error ("too few arguments to function `deg'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `deg'"); return; } lua_error ("incorrect arguments to function `deg'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (d*180./PI); lua_pushnumber (d*180./PI);
} }
@ -279,10 +279,10 @@ static void math_rad (void)
{ {
float d; float d;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (o == NULL) if (o == LUA_NOOBJECT)
{ lua_error ("too few arguments to function `rad'"); return; } lua_error ("too few arguments to function `rad'");
if (!lua_isnumber(o)) if (!lua_isnumber(o))
{ lua_error ("incorrect arguments to function `rad'"); return; } lua_error ("incorrect arguments to function `rad'");
d = lua_getnumber(o); d = lua_getnumber(o);
lua_pushnumber (d/180.*PI); lua_pushnumber (d/180.*PI);
} }

View File

@ -3,7 +3,7 @@
** String library to LUA ** String library to LUA
*/ */
char *rcs_strlib="$Id: strlib.c,v 1.5 1994/11/16 17:38:08 roberto Stab $"; char *rcs_strlib="$Id: strlib.c,v 1.6 1994/12/13 15:54:21 roberto Exp roberto $";
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@ -23,7 +23,7 @@ static void str_find (void)
lua_Object o1 = lua_getparam (1); lua_Object o1 = lua_getparam (1);
lua_Object o2 = lua_getparam (2); lua_Object o2 = lua_getparam (2);
if (!lua_isstring(o1) || !lua_isstring(o2)) if (!lua_isstring(o1) || !lua_isstring(o2))
{ lua_error ("incorrect arguments to function `strfind'"); return; } lua_error ("incorrect arguments to function `strfind'");
s1 = lua_getstring(o1); s1 = lua_getstring(o1);
s2 = lua_getstring(o2); s2 = lua_getstring(o2);
f = strstr(s1,s2); f = strstr(s1,s2);
@ -42,7 +42,7 @@ static void str_len (void)
{ {
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (!lua_isstring(o)) if (!lua_isstring(o))
{ lua_error ("incorrect arguments to function `strlen'"); return; } lua_error ("incorrect arguments to function `strlen'");
lua_pushnumber(strlen(lua_getstring(o))); lua_pushnumber(strlen(lua_getstring(o)));
} }
@ -60,9 +60,9 @@ static void str_sub (void)
lua_Object o2 = lua_getparam (2); lua_Object o2 = lua_getparam (2);
lua_Object o3 = lua_getparam (3); lua_Object o3 = lua_getparam (3);
if (!lua_isstring(o1) || !lua_isnumber(o2)) if (!lua_isstring(o1) || !lua_isnumber(o2))
{ lua_error ("incorrect arguments to function `strsub'"); return; } lua_error ("incorrect arguments to function `strsub'");
if (o3 != NULL && !lua_isnumber(o3)) if (o3 != LUA_NOOBJECT && !lua_isnumber(o3))
{ lua_error ("incorrect third argument to function `strsub'"); return; } lua_error ("incorrect third argument to function `strsub'");
s = lua_copystring(o1); s = lua_copystring(o1);
start = lua_getnumber (o2); start = lua_getnumber (o2);
end = o3 == NULL ? strlen(s) : lua_getnumber (o3); end = o3 == NULL ? strlen(s) : lua_getnumber (o3);
@ -86,7 +86,7 @@ static void str_lower (void)
char *s, *c; char *s, *c;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (!lua_isstring(o)) if (!lua_isstring(o))
{ lua_error ("incorrect arguments to function `strlower'"); return; } lua_error ("incorrect arguments to function `strlower'");
c = s = strdup(lua_getstring(o)); c = s = strdup(lua_getstring(o));
while (*c != 0) while (*c != 0)
{ {
@ -108,7 +108,7 @@ static void str_upper (void)
char *s, *c; char *s, *c;
lua_Object o = lua_getparam (1); lua_Object o = lua_getparam (1);
if (!lua_isstring(o)) if (!lua_isstring(o))
{ lua_error ("incorrect arguments to function `strlower'"); return; } lua_error ("incorrect arguments to function `strlower'");
c = s = strdup(lua_getstring(o)); c = s = strdup(lua_getstring(o));
while (*c != 0) while (*c != 0)
{ {