luaL check functions do not need the function name (it can be

accessed via luadebug interface).
This commit is contained in:
Roberto Ierusalimschy 1997-04-06 11:08:08 -03:00
parent 42fa305649
commit 3a9516ffc8
10 changed files with 129 additions and 125 deletions

View File

@ -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 <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "lua.h" #include "lua.h"
#include "auxlib.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 (!cond) {
if (extramsg == NULL) if (extramsg == NULL)
luaL_verror("bad argument #%d to function `%s'", numarg, funcname); 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); 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); 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 : 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); 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); 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 : 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) void luaL_openlib (struct luaL_reg *l, int n)

View File

@ -1,5 +1,5 @@
/* /*
** $Id: $ ** $Id: auxlib.h,v 1.1 1997/03/18 15:30:50 roberto Exp $
*/ */
#ifndef auxlib_h #ifndef auxlib_h
@ -13,11 +13,11 @@ struct luaL_reg {
}; };
void luaL_openlib (struct luaL_reg *l, int n); void luaL_openlib (struct luaL_reg *l, int n);
void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg); void luaL_arg_check(int cond, int numarg, char *extramsg);
char *luaL_check_string (int numArg, char *funcname); char *luaL_check_string (int numArg);
char *luaL_opt_string (int numArg, char *def, char *funcname); char *luaL_opt_string (int numArg, char *def);
double luaL_check_number (int numArg, char *funcname); double luaL_check_number (int numArg);
double luaL_opt_number (int numArg, double def, char *funcname); double luaL_opt_number (int numArg, double def);
void luaL_verror (char *fmt, ...); void luaL_verror (char *fmt, ...);
#endif #endif

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** 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 <stdio.h>
#include <string.h> #include <string.h>
@ -227,8 +227,8 @@ TObject *luaI_getim (int tag, IMS event)
void luaI_gettagmethod (void) void luaI_gettagmethod (void)
{ {
int t = (int)luaL_check_number(1, "gettagmethod"); int t = (int)luaL_check_number(1);
int e = luaI_checkevent(luaL_check_string(2, "gettagmethod"), luaI_eventname); int e = luaI_checkevent(luaL_check_string(2), luaI_eventname);
checktag(t); checktag(t);
if (validevent(t, e)) if (validevent(t, e))
luaI_pushobject(&luaI_IMtable[-t].int_method[e]); luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
@ -237,14 +237,14 @@ void luaI_gettagmethod (void)
void luaI_settagmethod (void) void luaI_settagmethod (void)
{ {
int t = (int)luaL_check_number(1, "settagmethod"); int t = (int)luaL_check_number(1);
int e = luaI_checkevent(luaL_check_string(2, "settagmethod"), luaI_eventname); int e = luaI_checkevent(luaL_check_string(2), luaI_eventname);
lua_Object func = lua_getparam(3); lua_Object func = lua_getparam(3);
checktag(t); checktag(t);
if (!validevent(t, e)) if (!validevent(t, e))
luaL_verror("cannot change internal method `%s' for tag %d", luaL_verror("cannot change internal method `%s' for tag %d",
luaI_eventname[e], t); 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"); 3, "function expected");
luaI_pushobject(&luaI_IMtable[-t].int_method[e]); luaI_pushobject(&luaI_IMtable[-t].int_method[e]);
luaI_IMtable[-t].int_method[e] = *luaI_Address(func); luaI_IMtable[-t].int_method[e] = *luaI_Address(func);
@ -262,7 +262,7 @@ TObject *luaI_geterrorim (void)
void luaI_seterrormethod (void) void luaI_seterrormethod (void)
{ {
lua_Object func = lua_getparam(1); 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"); 1, "function expected");
luaI_pushobject(&errorim); luaI_pushobject(&errorim);
errorim = *luaI_Address(func); errorim = *luaI_Address(func);
@ -321,10 +321,10 @@ void luaI_setfallback (void)
int e; int e;
TObject oldfunc; TObject oldfunc;
lua_CFunction replace; lua_CFunction replace;
char *name = luaL_check_string(1, "setfallback"); char *name = luaL_check_string(1);
lua_Object func = lua_getparam(2); lua_Object func = lua_getparam(2);
luaI_initfallbacks(); 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 */ if (strcmp(name, "error") == 0) { /* old error fallback */
oldfunc = errorim; oldfunc = errorim;
errorim = *luaI_Address(func); errorim = *luaI_Address(func);

6
hash.c
View File

@ -3,7 +3,7 @@
** hash manager for lua ** 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" #include "luamem.h"
@ -302,8 +302,8 @@ void lua_next (void)
Hash *t; Hash *t;
lua_Object o = lua_getparam(1); lua_Object o = lua_getparam(1);
lua_Object r = lua_getparam(2); lua_Object r = lua_getparam(2);
luaL_arg_check(lua_istable(o), "next", 1, "table expected"); luaL_arg_check(lua_istable(o), 1, "table expected");
luaL_arg_check(r != LUA_NOOBJECT, "next", 2, "value expected"); luaL_arg_check(r != LUA_NOOBJECT, 2, "value expected");
t = avalue(luaI_Address(o)); t = avalue(luaI_Address(o));
if (lua_isnil(r)) if (lua_isnil(r))
{ {

34
inout.c
View File

@ -5,7 +5,7 @@
** Also provides some predefined lua functions. ** 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 <stdio.h>
#include <string.h> #include <string.h>
@ -122,7 +122,7 @@ static int passresults (void)
*/ */
static void lua_internaldostring (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) if (passresults() == 0)
lua_pushuserdata(NULL); /* at least one result to signal no errors */ 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) 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 (lua_dofile(fname) == 0)
if (passresults() == 0) if (passresults() == 0)
lua_pushuserdata(NULL); /* at least one result to signal no errors */ 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) static void luaI_type (void)
{ {
lua_Object o = lua_getparam(1); 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_pushstring(luaI_typenames[-ttype(luaI_Address(o))]);
lua_pushnumber(lua_tag(o)); lua_pushnumber(lua_tag(o));
} }
@ -212,29 +212,29 @@ static void luaI_assert (void)
static void luaI_setglobal (void) static void luaI_setglobal (void)
{ {
lua_Object value = lua_getparam(2); 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_pushobject(value);
lua_setglobal(luaL_check_string(1, "setglobal")); lua_setglobal(luaL_check_string(1));
lua_pushobject(value); /* return given value */ lua_pushobject(value); /* return given value */
} }
static void luaI_rawsetglobal (void) static void luaI_rawsetglobal (void)
{ {
lua_Object value = lua_getparam(2); 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_pushobject(value);
lua_rawsetglobal(luaL_check_string(1, "rawsetglobal")); lua_rawsetglobal(luaL_check_string(1));
lua_pushobject(value); /* return given value */ lua_pushobject(value); /* return given value */
} }
static void luaI_getglobal (void) 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) 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) static void luatag (void)
@ -249,8 +249,8 @@ static void luaI_call (void)
lua_Object arg = lua_getparam(2); lua_Object arg = lua_getparam(2);
lua_Object temp, params[MAXPARAMS]; lua_Object temp, params[MAXPARAMS];
int narg, i; int narg, i;
luaL_arg_check(lua_isfunction(f), "call", 1, "function expected"); luaL_arg_check(lua_isfunction(f), 1, "function expected");
luaL_arg_check(lua_istable(arg), "call", 2, "table expected"); luaL_arg_check(lua_istable(arg), 2, "table expected");
/* narg = arg.n */ /* narg = arg.n */
lua_pushobject(arg); lua_pushobject(arg);
lua_pushstring("n"); lua_pushstring("n");
@ -280,9 +280,9 @@ static void luaI_call (void)
static void luaIl_settag (void) static void luaIl_settag (void)
{ {
lua_Object o = lua_getparam(1); 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_pushobject(o);
lua_settag(luaL_check_number(2, "settag")); lua_settag(luaL_check_number(2));
} }
static void luaIl_newtag (void) static void luaIl_newtag (void)
@ -294,8 +294,8 @@ static void rawgettable (void)
{ {
lua_Object t = lua_getparam(1); lua_Object t = lua_getparam(1);
lua_Object i = lua_getparam(2); lua_Object i = lua_getparam(2);
luaL_arg_check(t != LUA_NOOBJECT, "rawgettable", 1, NULL); luaL_arg_check(t != LUA_NOOBJECT, 1, NULL);
luaL_arg_check(i != LUA_NOOBJECT, "rawgettable", 2, NULL); luaL_arg_check(i != LUA_NOOBJECT, 2, NULL);
lua_pushobject(t); lua_pushobject(t);
lua_pushobject(i); lua_pushobject(i);
lua_pushobject(lua_rawgettable()); lua_pushobject(lua_rawgettable());
@ -307,7 +307,7 @@ static void rawsettable (void)
lua_Object i = lua_getparam(2); lua_Object i = lua_getparam(2);
lua_Object v = lua_getparam(3); lua_Object v = lua_getparam(3);
luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT, luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT,
"rawsettable", 0, NULL); 0, NULL);
lua_pushobject(t); lua_pushobject(t);
lua_pushobject(i); lua_pushobject(i);
lua_pushobject(v); lua_pushobject(v);

33
iolib.c
View File

@ -61,7 +61,7 @@ static void io_readfrom (void)
else if (lua_tag(f) == lua_tagio) else if (lua_tag(f) == lua_tagio)
lua_infile = lua_getuserdata(f); lua_infile = lua_getuserdata(f);
else { else {
char *s = luaL_check_string(1, "readfrom"); char *s = luaL_check_string(1);
FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r");
if (fp) if (fp)
lua_infile = fp; lua_infile = fp;
@ -82,7 +82,7 @@ static void io_writeto (void)
else if (lua_tag(f) == lua_tagio) else if (lua_tag(f) == lua_tagio)
lua_outfile = lua_getuserdata(f); lua_outfile = lua_getuserdata(f);
else { else {
char *s = luaL_check_string(1, "writeto"); char *s = luaL_check_string(1);
FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w");
if (fp) if (fp)
lua_outfile = fp; lua_outfile = fp;
@ -97,7 +97,7 @@ static void io_writeto (void)
static void io_appendto (void) static void io_appendto (void)
{ {
char *s = luaL_check_string(1, "appendto"); char *s = luaL_check_string(1);
FILE *fp = fopen (s, "a"); FILE *fp = fopen (s, "a");
if (fp != NULL) { if (fp != NULL) {
lua_outfile = fp; lua_outfile = fp;
@ -113,7 +113,7 @@ static void io_appendto (void)
static void io_read (void) static void io_read (void)
{ {
char *buff; 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 inskip = 0; /* to control {skips} */
int c = NEED_OTHER; int c = NEED_OTHER;
luaI_emptybuff(); luaI_emptybuff();
@ -164,7 +164,7 @@ static void io_write (void)
int arg = 1; int arg = 1;
int status = 1; int status = 1;
char *s; 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); status = status && (fputs(s, lua_outfile) != EOF);
pushresult(status); pushresult(status);
} }
@ -172,20 +172,20 @@ static void io_write (void)
static void io_execute (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) 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) static void io_rename (void)
{ {
pushresult(rename(luaL_check_string(1, "rename"), pushresult(rename(luaL_check_string(1),
luaL_check_string(2, "rename")) == 0); luaL_check_string(2)) == 0);
} }
@ -198,7 +198,7 @@ static void io_tmpname (void)
static void io_getenv (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; time_t t;
struct tm *tm; struct tm *tm;
char *s = luaL_opt_string(1, "%c", "date"); char *s = luaL_opt_string(1, "%c");
char b[BUFSIZ]; char b[BUFSIZ];
time(&t); tm = localtime(&t); time(&t); tm = localtime(&t);
if (strftime(b,sizeof(b),s,tm)) if (strftime(b,sizeof(b),s,tm))
@ -282,8 +282,8 @@ static void errorfb (void)
static void getbyte (void) static void getbyte (void)
{ {
lua_Object ud = lua_getparam(1); lua_Object ud = lua_getparam(1);
int i = luaL_opt_number(2, -1, "getbyte"); int i = luaL_opt_number(2, -1);
luaL_arg_check(lua_isuserdata(ud), "getbyte", 1, "userdata expected"); luaL_arg_check(lua_isuserdata(ud), 1, "userdata expected");
if (i == -1) if (i == -1)
lua_pushnumber(lua_getbindatasize(ud)); lua_pushnumber(lua_getbindatasize(ud));
else { else {
@ -298,10 +298,10 @@ static void getbyte (void)
static void createuserdata (void) static void createuserdata (void)
{ {
lua_Object t = lua_getparam(1); lua_Object t = lua_getparam(1);
int tag = luaL_opt_number(2, 0, "createud"); int tag = luaL_opt_number(2, 0);
int i; int i;
luaI_emptybuff(); 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++) { for (i=0; ; i++) {
lua_Object o; lua_Object o;
lua_beginblock(); lua_beginblock();
@ -312,8 +312,7 @@ static void createuserdata (void)
lua_endblock(); lua_endblock();
break; break;
} }
luaL_arg_check(lua_isnumber(o), "createud", 1, luaL_arg_check(lua_isnumber(o), 1, "table values must be numbers");
"table values must be numbers");
luaI_addchar(lua_getnumber(o)); luaI_addchar(lua_getnumber(o));
lua_endblock(); lua_endblock();
} }

View File

@ -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 #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 \ func.o: func.c luadebug.h lua.h table.h tree.h types.h opcode.h func.h \
luamem.h luamem.h
hash.o: hash.c luamem.h opcode.h lua.h types.h tree.h func.h hash.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.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 inout.h table.h hash.h luamem.h fallback.h
iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.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 luamem.o: luamem.c luamem.h lua.h
mathlib.o: mathlib.c lualib.h lua.h auxlib.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 \ 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 \ 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 tree.h func.h hash.h inout.h table.h
strlib.o: strlib.c lua.h auxlib.h lualib.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.o: table.c luamem.h auxlib.h lua.h opcode.h types.h tree.h \
table.h inout.h fallback.h luadebug.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 \ tree.o: tree.c luamem.h lua.h tree.h types.h lex.h hash.h opcode.h \
func.h table.h fallback.h func.h table.h fallback.h
undump.o: undump.c opcode.h lua.h types.h tree.h func.h luamem.h \ undump.o: undump.c opcode.h lua.h types.h tree.h func.h luamem.h \

View File

@ -3,7 +3,7 @@
** Mathematics library to LUA ** 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 <stdlib.h>
#include <math.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) static void math_abs (void)
{ {
double d = luaL_check_number(1, "abs"); double d = luaL_check_number(1);
if (d < 0) d = -d; if (d < 0) d = -d;
lua_pushnumber (d); lua_pushnumber (d);
} }
@ -28,7 +28,7 @@ static void math_abs (void)
static void math_sin (void) static void math_sin (void)
{ {
double d = luaL_check_number(1, "sin"); double d = luaL_check_number(1);
lua_pushnumber (sin(TORAD(d))); lua_pushnumber (sin(TORAD(d)));
} }
@ -36,7 +36,7 @@ static void math_sin (void)
static void math_cos (void) static void math_cos (void)
{ {
double d = luaL_check_number(1, "cos"); double d = luaL_check_number(1);
lua_pushnumber (cos(TORAD(d))); lua_pushnumber (cos(TORAD(d)));
} }
@ -44,82 +44,82 @@ static void math_cos (void)
static void math_tan (void) static void math_tan (void)
{ {
double d = luaL_check_number(1, "tan"); double d = luaL_check_number(1);
lua_pushnumber (tan(TORAD(d))); lua_pushnumber (tan(TORAD(d)));
} }
static void math_asin (void) static void math_asin (void)
{ {
double d = luaL_check_number(1, "asin"); double d = luaL_check_number(1);
lua_pushnumber (TODEGREE(asin(d))); lua_pushnumber (TODEGREE(asin(d)));
} }
static void math_acos (void) static void math_acos (void)
{ {
double d = luaL_check_number(1, "acos"); double d = luaL_check_number(1);
lua_pushnumber (TODEGREE(acos(d))); lua_pushnumber (TODEGREE(acos(d)));
} }
static void math_atan (void) static void math_atan (void)
{ {
double d = luaL_check_number(1, "atan"); double d = luaL_check_number(1);
lua_pushnumber (TODEGREE(atan(d))); lua_pushnumber (TODEGREE(atan(d)));
} }
static void math_atan2 (void) static void math_atan2 (void)
{ {
double d1 = luaL_check_number(1, "atan2"); double d1 = luaL_check_number(1);
double d2 = luaL_check_number(2, "atan2"); double d2 = luaL_check_number(2);
lua_pushnumber (TODEGREE(atan2(d1, d2))); lua_pushnumber (TODEGREE(atan2(d1, d2)));
} }
static void math_ceil (void) static void math_ceil (void)
{ {
double d = luaL_check_number(1, "ceil"); double d = luaL_check_number(1);
lua_pushnumber (ceil(d)); lua_pushnumber (ceil(d));
} }
static void math_floor (void) static void math_floor (void)
{ {
double d = luaL_check_number(1, "floor"); double d = luaL_check_number(1);
lua_pushnumber (floor(d)); lua_pushnumber (floor(d));
} }
static void math_mod (void) static void math_mod (void)
{ {
float x = luaL_check_number(1, "mod"); float x = luaL_check_number(1);
float y = luaL_check_number(2, "mod"); float y = luaL_check_number(2);
lua_pushnumber(fmod(x, y)); lua_pushnumber(fmod(x, y));
} }
static void math_sqrt (void) static void math_sqrt (void)
{ {
double d = luaL_check_number(1, "sqrt"); double d = luaL_check_number(1);
lua_pushnumber (sqrt(d)); lua_pushnumber (sqrt(d));
} }
static void math_pow (void) static void math_pow (void)
{ {
double d1 = luaL_check_number(1, "exp"); double d1 = luaL_check_number(1);
double d2 = luaL_check_number(2, "exp"); double d2 = luaL_check_number(2);
lua_pushnumber(pow(d1,d2)); lua_pushnumber(pow(d1,d2));
} }
static void math_min (void) static void math_min (void)
{ {
int i=1; int i=1;
double dmin = luaL_check_number(i, "min"); double dmin = luaL_check_number(i);
while (lua_getparam(++i) != LUA_NOOBJECT) while (lua_getparam(++i) != LUA_NOOBJECT)
{ {
double d = luaL_check_number(i, "min"); double d = luaL_check_number(i);
if (d < dmin) dmin = d; if (d < dmin) dmin = d;
} }
lua_pushnumber (dmin); lua_pushnumber (dmin);
@ -128,10 +128,10 @@ static void math_min (void)
static void math_max (void) static void math_max (void)
{ {
int i=1; int i=1;
double dmax = luaL_check_number(i, "max"); double dmax = luaL_check_number(i);
while (lua_getparam(++i) != LUA_NOOBJECT) while (lua_getparam(++i) != LUA_NOOBJECT)
{ {
double d = luaL_check_number(i, "max"); double d = luaL_check_number(i);
if (d > dmax) dmax = d; if (d > dmax) dmax = d;
} }
lua_pushnumber (dmax); lua_pushnumber (dmax);
@ -139,33 +139,33 @@ static void math_max (void)
static void math_log (void) static void math_log (void)
{ {
double d = luaL_check_number(1, "log"); double d = luaL_check_number(1);
lua_pushnumber (log(d)); lua_pushnumber (log(d));
} }
static void math_log10 (void) static void math_log10 (void)
{ {
double d = luaL_check_number(1, "log10"); double d = luaL_check_number(1);
lua_pushnumber (log10(d)); lua_pushnumber (log10(d));
} }
static void math_exp (void) static void math_exp (void)
{ {
double d = luaL_check_number(1, "exp"); double d = luaL_check_number(1);
lua_pushnumber (exp(d)); lua_pushnumber (exp(d));
} }
static void math_deg (void) static void math_deg (void)
{ {
float d = luaL_check_number(1, "deg"); float d = luaL_check_number(1);
lua_pushnumber (d*180./PI); lua_pushnumber (d*180./PI);
} }
static void math_rad (void) static void math_rad (void)
{ {
float d = luaL_check_number(1, "rad"); float d = luaL_check_number(1);
lua_pushnumber (d/180.*PI); lua_pushnumber (d/180.*PI);
} }
@ -176,7 +176,7 @@ static void math_random (void)
static void math_randomseed (void) static void math_randomseed (void)
{ {
srand(luaL_check_number(1, "randomseed")); srand(luaL_check_number(1));
} }

View File

@ -3,7 +3,7 @@
** String library to LUA ** 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 <string.h>
#include <stdio.h> #include <stdio.h>
@ -74,8 +74,8 @@ static void addstr (char *s)
*/ */
static void str_tok (void) static void str_tok (void)
{ {
char *s1 = luaL_check_string(1, "strtok"); char *s1 = luaL_check_string(1);
char *del = luaL_check_string(2, "strtok"); char *del = luaL_check_string(2);
lua_Object t = lua_createtable(); lua_Object t = lua_createtable();
int i = 1; int i = 1;
/* As strtok changes s1, and s1 is "constant", make a copy of it */ /* 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) 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) static void str_sub (void)
{ {
char *s = luaL_check_string(1, "strsub"); char *s = luaL_check_string(1);
long start = (long)luaL_check_number(2, "strsub"); long start = (long)luaL_check_number(2);
long end = (long)luaL_opt_number(3, strlen(s), "strsub"); long end = (long)luaL_opt_number(3, strlen(s));
if (1 <= start && start <= end && end <= strlen(s)) { if (1 <= start && start <= end && end <= strlen(s)) {
luaI_emptybuff(); luaI_emptybuff();
addnchar(s+start-1, end-start+1); addnchar(s+start-1, end-start+1);
@ -123,7 +123,7 @@ static void str_lower (void)
{ {
char *s; char *s;
luaI_emptybuff(); 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)); luaI_addchar(tolower((unsigned char)*s));
lua_pushstring(luaI_addchar(0)); lua_pushstring(luaI_addchar(0));
} }
@ -135,15 +135,15 @@ static void str_upper (void)
{ {
char *s; char *s;
luaI_emptybuff(); 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)); luaI_addchar(toupper((unsigned char)*s));
lua_pushstring(luaI_addchar(0)); lua_pushstring(luaI_addchar(0));
} }
static void str_rep (void) static void str_rep (void)
{ {
char *s = luaL_check_string(1, "strrep"); char *s = luaL_check_string(1);
int n = (int)luaL_check_number(2, "strrep"); int n = (int)luaL_check_number(2);
luaI_emptybuff(); luaI_emptybuff();
while (n-- > 0) while (n-- > 0)
addstr(s); addstr(s);
@ -155,9 +155,9 @@ static void str_rep (void)
*/ */
static void str_ascii (void) static void str_ascii (void)
{ {
char *s = luaL_check_string(1, "ascii"); char *s = luaL_check_string(1);
long pos = (long)luaL_opt_number(2, 1, "ascii") - 1; long pos = (long)luaL_opt_number(2, 1) - 1;
luaL_arg_check(0<=pos && pos<strlen(s), "ascii", 2, "out of range"); luaL_arg_check(0<=pos && pos<strlen(s), 2, "out of range");
lua_pushnumber((unsigned char)s[pos]); lua_pushnumber((unsigned char)s[pos]);
} }
@ -364,10 +364,10 @@ static char *match (char *s, char *p, int level)
static void str_find (void) static void str_find (void)
{ {
char *s = luaL_check_string(1, "strfind"); char *s = luaL_check_string(1);
char *p = luaL_check_string(2, "strfind"); char *p = luaL_check_string(2);
long init = (long)luaL_opt_number(3, 1, "strfind") - 1; long init = (long)luaL_opt_number(3, 1) - 1;
luaL_arg_check(0 <= init && init <= strlen(s), "strfind", 3, "out of range"); luaL_arg_check(0 <= init && init <= strlen(s), 3, "out of range");
if (lua_getparam(4) != LUA_NOOBJECT || if (lua_getparam(4) != LUA_NOOBJECT ||
strpbrk(p, SPECIALS) == NULL) { /* no special caracters? */ strpbrk(p, SPECIALS) == NULL) { /* no special caracters? */
char *s2 = strstr(s+init, p); char *s2 = strstr(s+init, p);
@ -420,15 +420,15 @@ static void add_s (lua_Object newp)
addstr(lua_isstring(res) ? lua_getstring(res) : ""); addstr(lua_isstring(res) ? lua_getstring(res) : "");
lua_endblock(); lua_endblock();
} }
else luaL_arg_check(0, "gsub", 3, NULL); else luaL_arg_check(0, 3, NULL);
} }
static void str_gsub (void) static void str_gsub (void)
{ {
char *src = luaL_check_string(1, "gsub"); char *src = luaL_check_string(1);
char *p = luaL_check_string(2, "gsub"); char *p = luaL_check_string(2);
lua_Object newp = lua_getparam(3); 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 anchor = (*p == '^') ? (p++, 1) : 0;
int n = 0; int n = 0;
luaI_emptybuff(); luaI_emptybuff();
@ -452,9 +452,9 @@ static void str_gsub (void)
static void str_set (void) static void str_set (void)
{ {
char *item = luaL_check_string(1, "strset"); char *item = luaL_check_string(1);
int i; 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(); luaI_emptybuff();
for (i=1; i<256; i++) /* 0 cannot be part of a set */ for (i=1; i<256; i++) /* 0 cannot be part of a set */
if (luaL_singlematch(i, item)) if (luaL_singlematch(i, item))
@ -479,7 +479,7 @@ void luaI_addquoted (char *s)
static void str_format (void) static void str_format (void)
{ {
int arg = 1; int arg = 1;
char *strfrmt = luaL_check_string(arg++, "format"); char *strfrmt = luaL_check_string(arg++);
luaI_emptybuff(); /* initialize */ luaI_emptybuff(); /* initialize */
while (*strfrmt) { while (*strfrmt) {
if (*strfrmt != '%') if (*strfrmt != '%')
@ -498,20 +498,20 @@ static void str_format (void)
buff = openspace(1000); /* to store the formated value */ buff = openspace(1000); /* to store the formated value */
switch (*strfrmt++) { switch (*strfrmt++) {
case 'q': case 'q':
luaI_addquoted(luaL_check_string(arg++, "format")); luaI_addquoted(luaL_check_string(arg++));
continue; continue;
case 's': { case 's': {
char *s = luaL_check_string(arg++, "format"); char *s = luaL_check_string(arg++);
buff = openspace(strlen(s)); buff = openspace(strlen(s));
sprintf(buff, form, s); sprintf(buff, form, s);
break; break;
} }
case 'c': case 'd': case 'i': case 'o': case 'c': case 'd': case 'i': case 'o':
case 'u': case 'x': case 'X': case 'u': case 'x': case 'X':
sprintf(buff, form, (int)luaL_check_number(arg++, "format")); sprintf(buff, form, (int)luaL_check_number(arg++));
break; break;
case 'e': case 'E': case 'f': case 'g': case 'e': case 'E': case 'f': case 'g':
sprintf(buff, form, luaL_check_number(arg++, "format")); sprintf(buff, form, luaL_check_number(arg++));
break; break;
default: /* also treat cases 'pnLlh' */ default: /* also treat cases 'pnLlh' */
lua_error("invalid format option in function `format'"); lua_error("invalid format option in function `format'");

View File

@ -3,7 +3,7 @@
** Module to control static tables ** 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 "luamem.h"
#include "auxlib.h" #include "auxlib.h"
@ -208,7 +208,7 @@ void luaI_nextvar (void)
if (lua_isnil(lua_getparam(1))) if (lua_isnil(lua_getparam(1)))
next = 0; next = 0;
else 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) while (next < lua_ntable && s_ttype(next) == LUA_T_NIL)
next++; next++;
if (next < lua_ntable) { if (next < lua_ntable) {