summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-06 11:08:08 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-04-06 11:08:08 -0300
commit3a9516ffc8de0d33051f83dc786dba615d6bac49 (patch)
tree9608796ca5abb4a724d70d99cb34dd818eb95662
parent42fa305649199712aad1c96beadb944b01277e3f (diff)
downloadlua-github-3a9516ffc8de0d33051f83dc786dba615d6bac49.tar.gz
luaL check functions do not need the function name (it can be
accessed via luadebug interface).
-rw-r--r--auxlib.c25
-rw-r--r--auxlib.h12
-rw-r--r--fallback.c18
-rw-r--r--hash.c6
-rw-r--r--inout.c34
-rw-r--r--iolib.c33
-rw-r--r--makefile10
-rw-r--r--mathlib.c54
-rw-r--r--strlib.c58
-rw-r--r--table.c4
10 files changed, 129 insertions, 125 deletions
diff --git a/auxlib.c b/auxlib.c
index ea3b7678..83087572 100644
--- a/auxlib.c
+++ b/auxlib.c
@@ -1,14 +1,19 @@
-char *rcs_auxlib="$Id: auxlib.c,v 1.1 1997/03/17 17:02:29 roberto Exp roberto $";
+char *rcs_auxlib="$Id: auxlib.c,v 1.2 1997/03/18 15:30:50 roberto Exp roberto $";
#include <stdio.h>
#include <stdarg.h>
#include "lua.h"
#include "auxlib.h"
+#include "luadebug.h"
-void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg)
+void luaL_arg_check(int cond, int numarg, char *extramsg)
{
+ char *funcname;
+ lua_getobjname(lua_stackedfunction(0), &funcname);
+ if (funcname == NULL)
+ funcname = "???";
if (!cond) {
if (extramsg == NULL)
luaL_verror("bad argument #%d to function `%s'", numarg, funcname);
@@ -18,31 +23,31 @@ void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg)
}
}
-char *luaL_check_string (int numArg, char *funcname)
+char *luaL_check_string (int numArg)
{
lua_Object o = lua_getparam(numArg);
- luaL_arg_check(lua_isstring(o), funcname, numArg, "string expected");
+ luaL_arg_check(lua_isstring(o), numArg, "string expected");
return lua_getstring(o);
}
-char *luaL_opt_string (int numArg, char *def, char *funcname)
+char *luaL_opt_string (int numArg, char *def)
{
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
- luaL_check_string(numArg, funcname);
+ luaL_check_string(numArg);
}
-double luaL_check_number (int numArg, char *funcname)
+double luaL_check_number (int numArg)
{
lua_Object o = lua_getparam(numArg);
- luaL_arg_check(lua_isnumber(o), funcname, numArg, "number expected");
+ luaL_arg_check(lua_isnumber(o), numArg, "number expected");
return lua_getnumber(o);
}
-double luaL_opt_number (int numArg, double def, char *funcname)
+double luaL_opt_number (int numArg, double def)
{
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
- luaL_check_number(numArg, funcname);
+ luaL_check_number(numArg);
}
void luaL_openlib (struct luaL_reg *l, int n)
diff --git a/auxlib.h b/auxlib.h
index 9e2556c7..c5897b3a 100644
--- a/auxlib.h
+++ b/auxlib.h
@@ -1,5 +1,5 @@
/*
-** $Id: $
+** $Id: auxlib.h,v 1.1 1997/03/18 15:30:50 roberto Exp $
*/
#ifndef auxlib_h
@@ -13,11 +13,11 @@ struct luaL_reg {
};
void luaL_openlib (struct luaL_reg *l, int n);
-void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg);
-char *luaL_check_string (int numArg, char *funcname);
-char *luaL_opt_string (int numArg, char *def, char *funcname);
-double luaL_check_number (int numArg, char *funcname);
-double luaL_opt_number (int numArg, double def, char *funcname);
+void luaL_arg_check(int cond, int numarg, char *extramsg);
+char *luaL_check_string (int numArg);
+char *luaL_opt_string (int numArg, char *def);
+double luaL_check_number (int numArg);
+double luaL_opt_number (int numArg, double def);
void luaL_verror (char *fmt, ...);
#endif
diff --git a/fallback.c b/fallback.c
index 220fefa1..25f52773 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio
*/
-char *rcs_fallback="$Id: fallback.c,v 2.1 1997/04/03 18:24:23 roberto Exp roberto $";
+char *rcs_fallback="$Id: fallback.c,v 2.2 1997/04/04 22:24:51 roberto Exp roberto $";
#include <stdio.h>
#include <string.h>
@@ -227,8 +227,8 @@ TObject *luaI_getim (int tag, IMS event)
void luaI_gettagmethod (void)
{
- int t = (int)luaL_check_number(1, "gettagmethod");
- int e = luaI_checkevent(luaL_check_string(2, "gettagmethod"), luaI_eventname);
+ int t = (int)luaL_check_number(1);
+ int e = luaI_checkevent(luaL_check_string(2), luaI_eventname);
checktag(t);
if (validevent(t, e))
luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
@@ -237,14 +237,14 @@ void luaI_gettagmethod (void)
void luaI_settagmethod (void)
{
- int t = (int)luaL_check_number(1, "settagmethod");
- int e = luaI_checkevent(luaL_check_string(2, "settagmethod"), luaI_eventname);
+ int t = (int)luaL_check_number(1);
+ int e = luaI_checkevent(luaL_check_string(2), luaI_eventname);
lua_Object func = lua_getparam(3);
checktag(t);
if (!validevent(t, e))
luaL_verror("cannot change internal method `%s' for tag %d",
luaI_eventname[e], t);
- luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "settagmethod",
+ luaL_arg_check(lua_isnil(func) || lua_isfunction(func),
3, "function expected");
luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
luaI_IMtable[-t].int_method[e] = *luaI_Address(func);
@@ -262,7 +262,7 @@ TObject *luaI_geterrorim (void)
void luaI_seterrormethod (void)
{
lua_Object func = lua_getparam(1);
- luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "seterrormethod",
+ luaL_arg_check(lua_isnil(func) || lua_isfunction(func),
1, "function expected");
luaI_pushobject(&errorim);
errorim = *luaI_Address(func);
@@ -321,10 +321,10 @@ void luaI_setfallback (void)
int e;
TObject oldfunc;
lua_CFunction replace;
- char *name = luaL_check_string(1, "setfallback");
+ char *name = luaL_check_string(1);
lua_Object func = lua_getparam(2);
luaI_initfallbacks();
- luaL_arg_check(lua_isfunction(func), "setfallback", 2, "function expected");
+ luaL_arg_check(lua_isfunction(func), 2, "function expected");
if (strcmp(name, "error") == 0) { /* old error fallback */
oldfunc = errorim;
errorim = *luaI_Address(func);
diff --git a/hash.c b/hash.c
index dcf3992a..a794d14f 100644
--- a/hash.c
+++ b/hash.c
@@ -3,7 +3,7 @@
** hash manager for lua
*/
-char *rcs_hash="$Id: hash.c,v 2.39 1997/03/31 14:17:09 roberto Exp roberto $";
+char *rcs_hash="$Id: hash.c,v 2.40 1997/04/04 15:35:37 roberto Exp roberto $";
#include "luamem.h"
@@ -302,8 +302,8 @@ void lua_next (void)
Hash *t;
lua_Object o = lua_getparam(1);
lua_Object r = lua_getparam(2);
- luaL_arg_check(lua_istable(o), "next", 1, "table expected");
- luaL_arg_check(r != LUA_NOOBJECT, "next", 2, "value expected");
+ luaL_arg_check(lua_istable(o), 1, "table expected");
+ luaL_arg_check(r != LUA_NOOBJECT, 2, "value expected");
t = avalue(luaI_Address(o));
if (lua_isnil(r))
{
diff --git a/inout.c b/inout.c
index 178ccd58..25390926 100644
--- a/inout.c
+++ b/inout.c
@@ -5,7 +5,7 @@
** Also provides some predefined lua functions.
*/
-char *rcs_inout="$Id: inout.c,v 2.54 1997/04/02 23:04:12 roberto Exp roberto $";
+char *rcs_inout="$Id: inout.c,v 2.55 1997/04/04 22:24:51 roberto Exp roberto $";
#include <stdio.h>
#include <string.h>
@@ -122,7 +122,7 @@ static int passresults (void)
*/
static void lua_internaldostring (void)
{
- if (lua_dostring(luaL_check_string(1, "dostring")) == 0)
+ if (lua_dostring(luaL_check_string(1)) == 0)
if (passresults() == 0)
lua_pushuserdata(NULL); /* at least one result to signal no errors */
}
@@ -132,7 +132,7 @@ static void lua_internaldostring (void)
*/
static void lua_internaldofile (void)
{
- char *fname = luaL_opt_string(1, NULL, "dofile");
+ char *fname = luaL_opt_string(1, NULL);
if (lua_dofile(fname) == 0)
if (passresults() == 0)
lua_pushuserdata(NULL); /* at least one result to signal no errors */
@@ -179,7 +179,7 @@ static void luaI_print (void)
static void luaI_type (void)
{
lua_Object o = lua_getparam(1);
- luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument");
+ luaL_arg_check(o != LUA_NOOBJECT, 1, "no argument");
lua_pushstring(luaI_typenames[-ttype(luaI_Address(o))]);
lua_pushnumber(lua_tag(o));
}
@@ -212,29 +212,29 @@ static void luaI_assert (void)
static void luaI_setglobal (void)
{
lua_Object value = lua_getparam(2);
- luaL_arg_check(value != LUA_NOOBJECT, "setglobal", 2, NULL);
+ luaL_arg_check(value != LUA_NOOBJECT, 2, NULL);
lua_pushobject(value);
- lua_setglobal(luaL_check_string(1, "setglobal"));
+ lua_setglobal(luaL_check_string(1));
lua_pushobject(value); /* return given value */
}
static void luaI_rawsetglobal (void)
{
lua_Object value = lua_getparam(2);
- luaL_arg_check(value != LUA_NOOBJECT, "rawsetglobal", 2, NULL);
+ luaL_arg_check(value != LUA_NOOBJECT, 2, NULL);
lua_pushobject(value);
- lua_rawsetglobal(luaL_check_string(1, "rawsetglobal"));
+ lua_rawsetglobal(luaL_check_string(1));
lua_pushobject(value); /* return given value */
}
static void luaI_getglobal (void)
{
- lua_pushobject(lua_getglobal(luaL_check_string(1, "getglobal")));
+ lua_pushobject(lua_getglobal(luaL_check_string(1)));
}
static void luaI_rawgetglobal (void)
{
- lua_pushobject(lua_rawgetglobal(luaL_check_string(1, "rawgetglobal")));
+ lua_pushobject(lua_rawgetglobal(luaL_check_string(1)));
}
static void luatag (void)
@@ -249,8 +249,8 @@ static void luaI_call (void)
lua_Object arg = lua_getparam(2);
lua_Object temp, params[MAXPARAMS];
int narg, i;
- luaL_arg_check(lua_isfunction(f), "call", 1, "function expected");
- luaL_arg_check(lua_istable(arg), "call", 2, "table expected");
+ luaL_arg_check(lua_isfunction(f), 1, "function expected");
+ luaL_arg_check(lua_istable(arg), 2, "table expected");
/* narg = arg.n */
lua_pushobject(arg);
lua_pushstring("n");
@@ -280,9 +280,9 @@ static void luaI_call (void)
static void luaIl_settag (void)
{
lua_Object o = lua_getparam(1);
- luaL_arg_check(o != LUA_NOOBJECT, "settag", 1, NULL);
+ luaL_arg_check(o != LUA_NOOBJECT, 1, NULL);
lua_pushobject(o);
- lua_settag(luaL_check_number(2, "settag"));
+ lua_settag(luaL_check_number(2));
}
static void luaIl_newtag (void)
@@ -294,8 +294,8 @@ static void rawgettable (void)
{
lua_Object t = lua_getparam(1);
lua_Object i = lua_getparam(2);
- luaL_arg_check(t != LUA_NOOBJECT, "rawgettable", 1, NULL);
- luaL_arg_check(i != LUA_NOOBJECT, "rawgettable", 2, NULL);
+ luaL_arg_check(t != LUA_NOOBJECT, 1, NULL);
+ luaL_arg_check(i != LUA_NOOBJECT, 2, NULL);
lua_pushobject(t);
lua_pushobject(i);
lua_pushobject(lua_rawgettable());
@@ -307,7 +307,7 @@ static void rawsettable (void)
lua_Object i = lua_getparam(2);
lua_Object v = lua_getparam(3);
luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT,
- "rawsettable", 0, NULL);
+ 0, NULL);
lua_pushobject(t);
lua_pushobject(i);
lua_pushobject(v);
diff --git a/iolib.c b/iolib.c
index 19a832f2..a3a6da22 100644
--- a/iolib.c
+++ b/iolib.c
@@ -61,7 +61,7 @@ static void io_readfrom (void)
else if (lua_tag(f) == lua_tagio)
lua_infile = lua_getuserdata(f);
else {
- char *s = luaL_check_string(1, "readfrom");
+ char *s = luaL_check_string(1);
FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
if (fp)
lua_infile = fp;
@@ -82,7 +82,7 @@ static void io_writeto (void)
else if (lua_tag(f) == lua_tagio)
lua_outfile = lua_getuserdata(f);
else {
- char *s = luaL_check_string(1, "writeto");
+ char *s = luaL_check_string(1);
FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w");
if (fp)
lua_outfile = fp;
@@ -97,7 +97,7 @@ static void io_writeto (void)
static void io_appendto (void)
{
- char *s = luaL_check_string(1, "appendto");
+ char *s = luaL_check_string(1);
FILE *fp = fopen (s, "a");
if (fp != NULL) {
lua_outfile = fp;
@@ -113,7 +113,7 @@ static void io_appendto (void)
static void io_read (void)
{
char *buff;
- char *p = luaL_opt_string(1, "[^\n]*{\n}", "read");
+ char *p = luaL_opt_string(1, "[^\n]*{\n}");
int inskip = 0; /* to control {skips} */
int c = NEED_OTHER;
luaI_emptybuff();
@@ -164,7 +164,7 @@ static void io_write (void)
int arg = 1;
int status = 1;
char *s;
- while ((s = luaL_opt_string(arg++, NULL, "write")) != NULL)
+ while ((s = luaL_opt_string(arg++, NULL)) != NULL)
status = status && (fputs(s, lua_outfile) != EOF);
pushresult(status);
}
@@ -172,20 +172,20 @@ static void io_write (void)
static void io_execute (void)
{
- lua_pushnumber(system(luaL_check_string(1, "execute")));
+ lua_pushnumber(system(luaL_check_string(1)));
}
static void io_remove (void)
{
- pushresult(remove(luaL_check_string(1, "remove")) == 0);
+ pushresult(remove(luaL_check_string(1)) == 0);
}
static void io_rename (void)
{
- pushresult(rename(luaL_check_string(1, "rename"),
- luaL_check_string(2, "rename")) == 0);
+ pushresult(rename(luaL_check_string(1),
+ luaL_check_string(2)) == 0);
}
@@ -198,7 +198,7 @@ static void io_tmpname (void)
static void io_getenv (void)
{
- lua_pushstring(getenv(luaL_check_string(1, "getenv"))); /* if NULL push nil */
+ lua_pushstring(getenv(luaL_check_string(1))); /* if NULL push nil */
}
@@ -206,7 +206,7 @@ static void io_date (void)
{
time_t t;
struct tm *tm;
- char *s = luaL_opt_string(1, "%c", "date");
+ char *s = luaL_opt_string(1, "%c");
char b[BUFSIZ];
time(&t); tm = localtime(&t);
if (strftime(b,sizeof(b),s,tm))
@@ -282,8 +282,8 @@ static void errorfb (void)
static void getbyte (void)
{
lua_Object ud = lua_getparam(1);
- int i = luaL_opt_number(2, -1, "getbyte");
- luaL_arg_check(lua_isuserdata(ud), "getbyte", 1, "userdata expected");
+ int i = luaL_opt_number(2, -1);
+ luaL_arg_check(lua_isuserdata(ud), 1, "userdata expected");
if (i == -1)
lua_pushnumber(lua_getbindatasize(ud));
else {
@@ -298,10 +298,10 @@ static void getbyte (void)
static void createuserdata (void)
{
lua_Object t = lua_getparam(1);
- int tag = luaL_opt_number(2, 0, "createud");
+ int tag = luaL_opt_number(2, 0);
int i;
luaI_emptybuff();
- luaL_arg_check(lua_istable(t), "createud", 1, "table expected");
+ luaL_arg_check(lua_istable(t), 1, "table expected");
for (i=0; ; i++) {
lua_Object o;
lua_beginblock();
@@ -312,8 +312,7 @@ static void createuserdata (void)
lua_endblock();
break;
}
- luaL_arg_check(lua_isnumber(o), "createud", 1,
- "table values must be numbers");
+ luaL_arg_check(lua_isnumber(o), 1, "table values must be numbers");
luaI_addchar(lua_getnumber(o));
lua_endblock();
}
diff --git a/makefile b/makefile
index debc3e61..60938925 100644
--- a/makefile
+++ b/makefile
@@ -1,4 +1,4 @@
-# $Id: makefile,v 1.31 1997/03/31 14:23:49 roberto Exp roberto $
+# $Id: makefile,v 1.32 1997/03/31 20:58:42 roberto Exp roberto $
#configuration
@@ -83,7 +83,7 @@ fallback.o: fallback.c auxlib.h lua.h luamem.h fallback.h opcode.h \
func.o: func.c luadebug.h lua.h table.h tree.h types.h opcode.h func.h \
luamem.h
hash.o: hash.c luamem.h opcode.h lua.h types.h tree.h func.h hash.h \
- table.h
+ table.h auxlib.h
inout.o: inout.c auxlib.h lua.h lex.h opcode.h types.h tree.h func.h \
inout.h table.h hash.h luamem.h fallback.h
iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.h
@@ -93,12 +93,12 @@ lua.o: lua.c lua.h lualib.h
luamem.o: luamem.c luamem.h lua.h
mathlib.o: mathlib.c lualib.h lua.h auxlib.h
opcode.o: opcode.c luadebug.h lua.h luamem.h opcode.h types.h tree.h \
- func.h hash.h inout.h table.h fallback.h undump.h
+ func.h hash.h inout.h table.h fallback.h undump.h auxlib.h
parser.o: parser.c luadebug.h lua.h luamem.h lex.h opcode.h types.h \
tree.h func.h hash.h inout.h table.h
strlib.o: strlib.c lua.h auxlib.h lualib.h
-table.o: table.c luamem.h opcode.h lua.h types.h tree.h func.h hash.h \
- table.h inout.h fallback.h luadebug.h
+table.o: table.c luamem.h auxlib.h lua.h opcode.h types.h tree.h \
+ func.h hash.h table.h inout.h fallback.h luadebug.h
tree.o: tree.c luamem.h lua.h tree.h types.h lex.h hash.h opcode.h \
func.h table.h fallback.h
undump.o: undump.c opcode.h lua.h types.h tree.h func.h luamem.h \
diff --git a/mathlib.c b/mathlib.c
index 7a74fe14..1774f7aa 100644
--- a/mathlib.c
+++ b/mathlib.c
@@ -3,7 +3,7 @@
** Mathematics library to LUA
*/
-char *rcs_mathlib="$Id: mathlib.c,v 1.21 1997/03/21 18:37:28 roberto Exp roberto $";
+char *rcs_mathlib="$Id: mathlib.c,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $";
#include <stdlib.h>
#include <math.h>
@@ -20,7 +20,7 @@ char *rcs_mathlib="$Id: mathlib.c,v 1.21 1997/03/21 18:37:28 roberto Exp roberto
static void math_abs (void)
{
- double d = luaL_check_number(1, "abs");
+ double d = luaL_check_number(1);
if (d < 0) d = -d;
lua_pushnumber (d);
}
@@ -28,7 +28,7 @@ static void math_abs (void)
static void math_sin (void)
{
- double d = luaL_check_number(1, "sin");
+ double d = luaL_check_number(1);
lua_pushnumber (sin(TORAD(d)));
}
@@ -36,7 +36,7 @@ static void math_sin (void)
static void math_cos (void)
{
- double d = luaL_check_number(1, "cos");
+ double d = luaL_check_number(1);
lua_pushnumber (cos(TORAD(d)));
}
@@ -44,82 +44,82 @@ static void math_cos (void)
static void math_tan (void)
{
- double d = luaL_check_number(1, "tan");
+ double d = luaL_check_number(1);
lua_pushnumber (tan(TORAD(d)));
}
static void math_asin (void)
{
- double d = luaL_check_number(1, "asin");
+ double d = luaL_check_number(1);
lua_pushnumber (TODEGREE(asin(d)));
}
static void math_acos (void)
{
- double d = luaL_check_number(1, "acos");
+ double d = luaL_check_number(1);
lua_pushnumber (TODEGREE(acos(d)));
}
static void math_atan (void)
{
- double d = luaL_check_number(1, "atan");
+ double d = luaL_check_number(1);
lua_pushnumber (TODEGREE(atan(d)));
}
static void math_atan2 (void)
{
- double d1 = luaL_check_number(1, "atan2");
- double d2 = luaL_check_number(2, "atan2");
+ double d1 = luaL_check_number(1);
+ double d2 = luaL_check_number(2);
lua_pushnumber (TODEGREE(atan2(d1, d2)));
}
static void math_ceil (void)
{
- double d = luaL_check_number(1, "ceil");
+ double d = luaL_check_number(1);
lua_pushnumber (ceil(d));
}
static void math_floor (void)
{
- double d = luaL_check_number(1, "floor");
+ double d = luaL_check_number(1);
lua_pushnumber (floor(d));
}
static void math_mod (void)
{
- float x = luaL_check_number(1, "mod");
- float y = luaL_check_number(2, "mod");
+ float x = luaL_check_number(1);
+ float y = luaL_check_number(2);
lua_pushnumber(fmod(x, y));
}
static void math_sqrt (void)
{
- double d = luaL_check_number(1, "sqrt");
+ double d = luaL_check_number(1);
lua_pushnumber (sqrt(d));
}
static void math_pow (void)
{
- double d1 = luaL_check_number(1, "exp");
- double d2 = luaL_check_number(2, "exp");
+ double d1 = luaL_check_number(1);
+ double d2 = luaL_check_number(2);
lua_pushnumber(pow(d1,d2));
}
static void math_min (void)
{
int i=1;
- double dmin = luaL_check_number(i, "min");
+ double dmin = luaL_check_number(i);
while (lua_getparam(++i) != LUA_NOOBJECT)
{
- double d = luaL_check_number(i, "min");
+ double d = luaL_check_number(i);
if (d < dmin) dmin = d;
}
lua_pushnumber (dmin);
@@ -128,10 +128,10 @@ static void math_min (void)
static void math_max (void)
{
int i=1;
- double dmax = luaL_check_number(i, "max");
+ double dmax = luaL_check_number(i);
while (lua_getparam(++i) != LUA_NOOBJECT)
{
- double d = luaL_check_number(i, "max");
+ double d = luaL_check_number(i);
if (d > dmax) dmax = d;
}
lua_pushnumber (dmax);
@@ -139,33 +139,33 @@ static void math_max (void)
static void math_log (void)
{
- double d = luaL_check_number(1, "log");
+ double d = luaL_check_number(1);
lua_pushnumber (log(d));
}
static void math_log10 (void)
{
- double d = luaL_check_number(1, "log10");
+ double d = luaL_check_number(1);
lua_pushnumber (log10(d));
}
static void math_exp (void)
{
- double d = luaL_check_number(1, "exp");
+ double d = luaL_check_number(1);
lua_pushnumber (exp(d));
}
static void math_deg (void)
{
- float d = luaL_check_number(1, "deg");
+ float d = luaL_check_number(1);
lua_pushnumber (d*180./PI);
}
static void math_rad (void)
{
- float d = luaL_check_number(1, "rad");
+ float d = luaL_check_number(1);
lua_pushnumber (d/180.*PI);
}
@@ -176,7 +176,7 @@ static void math_random (void)
static void math_randomseed (void)
{
- srand(luaL_check_number(1, "randomseed"));
+ srand(luaL_check_number(1));
}
diff --git a/strlib.c b/strlib.c
index 8b57e391..6aa726bc 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
** String library to LUA
*/
-char *rcs_strlib="$Id: strlib.c,v 1.38 1997/03/26 22:23:15 roberto Exp roberto $";
+char *rcs_strlib="$Id: strlib.c,v 1.39 1997/04/04 22:24:51 roberto Exp roberto $";
#include <string.h>
#include <stdio.h>
@@ -74,8 +74,8 @@ static void addstr (char *s)
*/
static void str_tok (void)
{
- char *s1 = luaL_check_string(1, "strtok");
- char *del = luaL_check_string(2, "strtok");
+ char *s1 = luaL_check_string(1);
+ char *del = luaL_check_string(2);
lua_Object t = lua_createtable();
int i = 1;
/* As strtok changes s1, and s1 is "constant", make a copy of it */
@@ -97,7 +97,7 @@ static void str_tok (void)
*/
static void str_len (void)
{
- lua_pushnumber(strlen(luaL_check_string(1, "strlen")));
+ lua_pushnumber(strlen(luaL_check_string(1)));
}
/*
@@ -105,9 +105,9 @@ static void str_len (void)
*/
static void str_sub (void)
{
- char *s = luaL_check_string(1, "strsub");
- long start = (long)luaL_check_number(2, "strsub");
- long end = (long)luaL_opt_number(3, strlen(s), "strsub");
+ char *s = luaL_check_string(1);
+ long start = (long)luaL_check_number(2);
+ long end = (long)luaL_opt_number(3, strlen(s));
if (1 <= start && start <= end && end <= strlen(s)) {
luaI_emptybuff();
addnchar(s+start-1, end-start+1);
@@ -123,7 +123,7 @@ static void str_lower (void)
{
char *s;
luaI_emptybuff();
- for (s = luaL_check_string(1, "strlower"); *s; s++)
+ for (s = luaL_check_string(1); *s; s++)
luaI_addchar(tolower((unsigned char)*s));
lua_pushstring(luaI_addchar(0));
}
@@ -135,15 +135,15 @@ static void str_upper (void)
{
char *s;
luaI_emptybuff();
- for (s = luaL_check_string(1, "strupper"); *s; s++)
+ for (s = luaL_check_string(1); *s; s++)
luaI_addchar(toupper((unsigned char)*s));
lua_pushstring(luaI_addchar(0));
}
static void str_rep (void)
{
- char *s = luaL_check_string(1, "strrep");
- int n = (int)luaL_check_number(2, "strrep");
+ char *s = luaL_check_string(1);
+ int n = (int)luaL_check_number(2);
luaI_emptybuff();
while (n-- > 0)
addstr(s);
@@ -155,9 +155,9 @@ static void str_rep (void)
*/
static void str_ascii (void)
{
- char *s = luaL_check_string(1, "ascii");
- long pos = (long)luaL_opt_number(2, 1, "ascii") - 1;
- luaL_arg_check(0<=pos && pos<strlen(s), "ascii", 2, "out of range");
+ char *s = luaL_check_string(1);
+ long pos = (long)luaL_opt_number(2, 1) - 1;
+ luaL_arg_check(0<=pos && pos<strlen(s), 2, "out of range");
lua_pushnumber((unsigned char)s[pos]);
}
@@ -364,10 +364,10 @@ static char *match (char *s, char *p, int level)
static void str_find (void)
{
- char *s = luaL_check_string(1, "strfind");
- char *p = luaL_check_string(2, "strfind");
- long init = (long)luaL_opt_number(3, 1, "strfind") - 1;
- luaL_arg_check(0 <= init && init <= strlen(s), "strfind", 3, "out of range");
+ char *s = luaL_check_string(1);
+ char *p = luaL_check_string(2);
+ long init = (long)luaL_opt_number(3, 1) - 1;
+ luaL_arg_check(0 <= init && init <= strlen(s), 3, "out of range");
if (lua_getparam(4) != LUA_NOOBJECT ||
strpbrk(p, SPECIALS) == NULL) { /* no special caracters? */
char *s2 = strstr(s+init, p);
@@ -420,15 +420,15 @@ static void add_s (lua_Object newp)
addstr(lua_isstring(res) ? lua_getstring(res) : "");
lua_endblock();
}
- else luaL_arg_check(0, "gsub", 3, NULL);
+ else luaL_arg_check(0, 3, NULL);
}
static void str_gsub (void)
{
- char *src = luaL_check_string(1, "gsub");
- char *p = luaL_check_string(2, "gsub");
+ char *src = luaL_check_string(1);
+ char *p = luaL_check_string(2);
lua_Object newp = lua_getparam(3);
- int max_s = (int)luaL_opt_number(4, strlen(src)+1, "gsub");
+ int max_s = (int)luaL_opt_number(4, strlen(src)+1);
int anchor = (*p == '^') ? (p++, 1) : 0;
int n = 0;
luaI_emptybuff();
@@ -452,9 +452,9 @@ static void str_gsub (void)
static void str_set (void)
{
- char *item = luaL_check_string(1, "strset");
+ char *item = luaL_check_string(1);
int i;
- luaL_arg_check(*luaL_item_end(item) == 0, "strset", 1, "wrong format");
+ luaL_arg_check(*luaL_item_end(item) == 0, 1, "wrong format");
luaI_emptybuff();
for (i=1; i<256; i++) /* 0 cannot be part of a set */
if (luaL_singlematch(i, item))
@@ -479,7 +479,7 @@ void luaI_addquoted (char *s)
static void str_format (void)
{
int arg = 1;
- char *strfrmt = luaL_check_string(arg++, "format");
+ char *strfrmt = luaL_check_string(arg++);
luaI_emptybuff(); /* initialize */
while (*strfrmt) {
if (*strfrmt != '%')
@@ -498,20 +498,20 @@ static void str_format (void)
buff = openspace(1000); /* to store the formated value */
switch (*strfrmt++) {
case 'q':
- luaI_addquoted(luaL_check_string(arg++, "format"));
+ luaI_addquoted(luaL_check_string(arg++));
continue;
case 's': {
- char *s = luaL_check_string(arg++, "format");
+ char *s = luaL_check_string(arg++);
buff = openspace(strlen(s));
sprintf(buff, form, s);
break;
}
case 'c': case 'd': case 'i': case 'o':
case 'u': case 'x': case 'X':
- sprintf(buff, form, (int)luaL_check_number(arg++, "format"));
+ sprintf(buff, form, (int)luaL_check_number(arg++));
break;
case 'e': case 'E': case 'f': case 'g':
- sprintf(buff, form, luaL_check_number(arg++, "format"));
+ sprintf(buff, form, luaL_check_number(arg++));
break;
default: /* also treat cases 'pnLlh' */
lua_error("invalid format option in function `format'");
diff --git a/table.c b/table.c
index 2bef4d0f..a1ab1178 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
** Module to control static tables
*/
-char *rcs_table="$Id: table.c,v 2.65 1997/03/31 14:17:09 roberto Exp roberto $";
+char *rcs_table="$Id: table.c,v 2.66 1997/04/04 15:35:37 roberto Exp roberto $";
#include "luamem.h"
#include "auxlib.h"
@@ -208,7 +208,7 @@ void luaI_nextvar (void)
if (lua_isnil(lua_getparam(1)))
next = 0;
else
- next = luaI_findsymbolbyname(luaL_check_string(1, "nextvar")) + 1;
+ next = luaI_findsymbolbyname(luaL_check_string(1)) + 1;
while (next < lua_ntable && s_ttype(next) == LUA_T_NIL)
next++;
if (next < lua_ntable) {