diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-06 11:08:08 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-06 11:08:08 -0300 |
| commit | 3a9516ffc8de0d33051f83dc786dba615d6bac49 (patch) | |
| tree | 9608796ca5abb4a724d70d99cb34dd818eb95662 | |
| parent | 42fa305649199712aad1c96beadb944b01277e3f (diff) | |
| download | lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.tar.gz lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.tar.bz2 lua-3a9516ffc8de0d33051f83dc786dba615d6bac49.zip | |
luaL check functions do not need the function name (it can be
accessed via luadebug interface).
| -rw-r--r-- | auxlib.c | 25 | ||||
| -rw-r--r-- | auxlib.h | 12 | ||||
| -rw-r--r-- | fallback.c | 18 | ||||
| -rw-r--r-- | hash.c | 6 | ||||
| -rw-r--r-- | inout.c | 34 | ||||
| -rw-r--r-- | iolib.c | 33 | ||||
| -rw-r--r-- | makefile | 10 | ||||
| -rw-r--r-- | mathlib.c | 54 | ||||
| -rw-r--r-- | strlib.c | 58 | ||||
| -rw-r--r-- | table.c | 4 |
10 files changed, 129 insertions, 125 deletions
| @@ -1,14 +1,19 @@ | |||
| 1 | char *rcs_auxlib="$Id: auxlib.c,v 1.1 1997/03/17 17:02:29 roberto Exp roberto $"; | 1 | char *rcs_auxlib="$Id: auxlib.c,v 1.2 1997/03/18 15:30:50 roberto Exp roberto $"; |
| 2 | 2 | ||
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <stdarg.h> | 4 | #include <stdarg.h> |
| 5 | 5 | ||
| 6 | #include "lua.h" | 6 | #include "lua.h" |
| 7 | #include "auxlib.h" | 7 | #include "auxlib.h" |
| 8 | #include "luadebug.h" | ||
| 8 | 9 | ||
| 9 | 10 | ||
| 10 | void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg) | 11 | void luaL_arg_check(int cond, int numarg, char *extramsg) |
| 11 | { | 12 | { |
| 13 | char *funcname; | ||
| 14 | lua_getobjname(lua_stackedfunction(0), &funcname); | ||
| 15 | if (funcname == NULL) | ||
| 16 | funcname = "???"; | ||
| 12 | if (!cond) { | 17 | if (!cond) { |
| 13 | if (extramsg == NULL) | 18 | if (extramsg == NULL) |
| 14 | luaL_verror("bad argument #%d to function `%s'", numarg, funcname); | 19 | 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) | |||
| 18 | } | 23 | } |
| 19 | } | 24 | } |
| 20 | 25 | ||
| 21 | char *luaL_check_string (int numArg, char *funcname) | 26 | char *luaL_check_string (int numArg) |
| 22 | { | 27 | { |
| 23 | lua_Object o = lua_getparam(numArg); | 28 | lua_Object o = lua_getparam(numArg); |
| 24 | luaL_arg_check(lua_isstring(o), funcname, numArg, "string expected"); | 29 | luaL_arg_check(lua_isstring(o), numArg, "string expected"); |
| 25 | return lua_getstring(o); | 30 | return lua_getstring(o); |
| 26 | } | 31 | } |
| 27 | 32 | ||
| 28 | char *luaL_opt_string (int numArg, char *def, char *funcname) | 33 | char *luaL_opt_string (int numArg, char *def) |
| 29 | { | 34 | { |
| 30 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : | 35 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : |
| 31 | luaL_check_string(numArg, funcname); | 36 | luaL_check_string(numArg); |
| 32 | } | 37 | } |
| 33 | 38 | ||
| 34 | double luaL_check_number (int numArg, char *funcname) | 39 | double luaL_check_number (int numArg) |
| 35 | { | 40 | { |
| 36 | lua_Object o = lua_getparam(numArg); | 41 | lua_Object o = lua_getparam(numArg); |
| 37 | luaL_arg_check(lua_isnumber(o), funcname, numArg, "number expected"); | 42 | luaL_arg_check(lua_isnumber(o), numArg, "number expected"); |
| 38 | return lua_getnumber(o); | 43 | return lua_getnumber(o); |
| 39 | } | 44 | } |
| 40 | 45 | ||
| 41 | 46 | ||
| 42 | double luaL_opt_number (int numArg, double def, char *funcname) | 47 | double luaL_opt_number (int numArg, double def) |
| 43 | { | 48 | { |
| 44 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : | 49 | return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : |
| 45 | luaL_check_number(numArg, funcname); | 50 | luaL_check_number(numArg); |
| 46 | } | 51 | } |
| 47 | 52 | ||
| 48 | void luaL_openlib (struct luaL_reg *l, int n) | 53 | void luaL_openlib (struct luaL_reg *l, int n) |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: $ | 2 | ** $Id: auxlib.h,v 1.1 1997/03/18 15:30:50 roberto Exp $ |
| 3 | */ | 3 | */ |
| 4 | 4 | ||
| 5 | #ifndef auxlib_h | 5 | #ifndef auxlib_h |
| @@ -13,11 +13,11 @@ struct luaL_reg { | |||
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | void luaL_openlib (struct luaL_reg *l, int n); | 15 | void luaL_openlib (struct luaL_reg *l, int n); |
| 16 | void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg); | 16 | void luaL_arg_check(int cond, int numarg, char *extramsg); |
| 17 | char *luaL_check_string (int numArg, char *funcname); | 17 | char *luaL_check_string (int numArg); |
| 18 | char *luaL_opt_string (int numArg, char *def, char *funcname); | 18 | char *luaL_opt_string (int numArg, char *def); |
| 19 | double luaL_check_number (int numArg, char *funcname); | 19 | double luaL_check_number (int numArg); |
| 20 | double luaL_opt_number (int numArg, double def, char *funcname); | 20 | double luaL_opt_number (int numArg, double def); |
| 21 | void luaL_verror (char *fmt, ...); | 21 | void luaL_verror (char *fmt, ...); |
| 22 | 22 | ||
| 23 | #endif | 23 | #endif |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_fallback="$Id: fallback.c,v 2.1 1997/04/03 18:24:23 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 2.2 1997/04/04 22:24:51 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -227,8 +227,8 @@ TObject *luaI_getim (int tag, IMS event) | |||
| 227 | 227 | ||
| 228 | void luaI_gettagmethod (void) | 228 | void luaI_gettagmethod (void) |
| 229 | { | 229 | { |
| 230 | int t = (int)luaL_check_number(1, "gettagmethod"); | 230 | int t = (int)luaL_check_number(1); |
| 231 | int e = luaI_checkevent(luaL_check_string(2, "gettagmethod"), luaI_eventname); | 231 | int e = luaI_checkevent(luaL_check_string(2), luaI_eventname); |
| 232 | checktag(t); | 232 | checktag(t); |
| 233 | if (validevent(t, e)) | 233 | if (validevent(t, e)) |
| 234 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); | 234 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); |
| @@ -237,14 +237,14 @@ void luaI_gettagmethod (void) | |||
| 237 | 237 | ||
| 238 | void luaI_settagmethod (void) | 238 | void luaI_settagmethod (void) |
| 239 | { | 239 | { |
| 240 | int t = (int)luaL_check_number(1, "settagmethod"); | 240 | int t = (int)luaL_check_number(1); |
| 241 | int e = luaI_checkevent(luaL_check_string(2, "settagmethod"), luaI_eventname); | 241 | int e = luaI_checkevent(luaL_check_string(2), luaI_eventname); |
| 242 | lua_Object func = lua_getparam(3); | 242 | lua_Object func = lua_getparam(3); |
| 243 | checktag(t); | 243 | checktag(t); |
| 244 | if (!validevent(t, e)) | 244 | if (!validevent(t, e)) |
| 245 | luaL_verror("cannot change internal method `%s' for tag %d", | 245 | luaL_verror("cannot change internal method `%s' for tag %d", |
| 246 | luaI_eventname[e], t); | 246 | luaI_eventname[e], t); |
| 247 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "settagmethod", | 247 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), |
| 248 | 3, "function expected"); | 248 | 3, "function expected"); |
| 249 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); | 249 | luaI_pushobject(&luaI_IMtable[-t].int_method[e]); |
| 250 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); | 250 | luaI_IMtable[-t].int_method[e] = *luaI_Address(func); |
| @@ -262,7 +262,7 @@ TObject *luaI_geterrorim (void) | |||
| 262 | void luaI_seterrormethod (void) | 262 | void luaI_seterrormethod (void) |
| 263 | { | 263 | { |
| 264 | lua_Object func = lua_getparam(1); | 264 | lua_Object func = lua_getparam(1); |
| 265 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), "seterrormethod", | 265 | luaL_arg_check(lua_isnil(func) || lua_isfunction(func), |
| 266 | 1, "function expected"); | 266 | 1, "function expected"); |
| 267 | luaI_pushobject(&errorim); | 267 | luaI_pushobject(&errorim); |
| 268 | errorim = *luaI_Address(func); | 268 | errorim = *luaI_Address(func); |
| @@ -321,10 +321,10 @@ void luaI_setfallback (void) | |||
| 321 | int e; | 321 | int e; |
| 322 | TObject oldfunc; | 322 | TObject oldfunc; |
| 323 | lua_CFunction replace; | 323 | lua_CFunction replace; |
| 324 | char *name = luaL_check_string(1, "setfallback"); | 324 | char *name = luaL_check_string(1); |
| 325 | lua_Object func = lua_getparam(2); | 325 | lua_Object func = lua_getparam(2); |
| 326 | luaI_initfallbacks(); | 326 | luaI_initfallbacks(); |
| 327 | luaL_arg_check(lua_isfunction(func), "setfallback", 2, "function expected"); | 327 | luaL_arg_check(lua_isfunction(func), 2, "function expected"); |
| 328 | if (strcmp(name, "error") == 0) { /* old error fallback */ | 328 | if (strcmp(name, "error") == 0) { /* old error fallback */ |
| 329 | oldfunc = errorim; | 329 | oldfunc = errorim; |
| 330 | errorim = *luaI_Address(func); | 330 | errorim = *luaI_Address(func); |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** hash manager for lua | 3 | ** hash manager for lua |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_hash="$Id: hash.c,v 2.39 1997/03/31 14:17:09 roberto Exp roberto $"; | 6 | char *rcs_hash="$Id: hash.c,v 2.40 1997/04/04 15:35:37 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | #include "luamem.h" | 9 | #include "luamem.h" |
| @@ -302,8 +302,8 @@ void lua_next (void) | |||
| 302 | Hash *t; | 302 | Hash *t; |
| 303 | lua_Object o = lua_getparam(1); | 303 | lua_Object o = lua_getparam(1); |
| 304 | lua_Object r = lua_getparam(2); | 304 | lua_Object r = lua_getparam(2); |
| 305 | luaL_arg_check(lua_istable(o), "next", 1, "table expected"); | 305 | luaL_arg_check(lua_istable(o), 1, "table expected"); |
| 306 | luaL_arg_check(r != LUA_NOOBJECT, "next", 2, "value expected"); | 306 | luaL_arg_check(r != LUA_NOOBJECT, 2, "value expected"); |
| 307 | t = avalue(luaI_Address(o)); | 307 | t = avalue(luaI_Address(o)); |
| 308 | if (lua_isnil(r)) | 308 | if (lua_isnil(r)) |
| 309 | { | 309 | { |
| @@ -5,7 +5,7 @@ | |||
| 5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | char *rcs_inout="$Id: inout.c,v 2.54 1997/04/02 23:04:12 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.55 1997/04/04 22:24:51 roberto Exp roberto $"; |
| 9 | 9 | ||
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | #include <string.h> | 11 | #include <string.h> |
| @@ -122,7 +122,7 @@ static int passresults (void) | |||
| 122 | */ | 122 | */ |
| 123 | static void lua_internaldostring (void) | 123 | static void lua_internaldostring (void) |
| 124 | { | 124 | { |
| 125 | if (lua_dostring(luaL_check_string(1, "dostring")) == 0) | 125 | if (lua_dostring(luaL_check_string(1)) == 0) |
| 126 | if (passresults() == 0) | 126 | if (passresults() == 0) |
| 127 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ | 127 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ |
| 128 | } | 128 | } |
| @@ -132,7 +132,7 @@ static void lua_internaldostring (void) | |||
| 132 | */ | 132 | */ |
| 133 | static void lua_internaldofile (void) | 133 | static void lua_internaldofile (void) |
| 134 | { | 134 | { |
| 135 | char *fname = luaL_opt_string(1, NULL, "dofile"); | 135 | char *fname = luaL_opt_string(1, NULL); |
| 136 | if (lua_dofile(fname) == 0) | 136 | if (lua_dofile(fname) == 0) |
| 137 | if (passresults() == 0) | 137 | if (passresults() == 0) |
| 138 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ | 138 | lua_pushuserdata(NULL); /* at least one result to signal no errors */ |
| @@ -179,7 +179,7 @@ static void luaI_print (void) | |||
| 179 | static void luaI_type (void) | 179 | static void luaI_type (void) |
| 180 | { | 180 | { |
| 181 | lua_Object o = lua_getparam(1); | 181 | lua_Object o = lua_getparam(1); |
| 182 | luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument"); | 182 | luaL_arg_check(o != LUA_NOOBJECT, 1, "no argument"); |
| 183 | lua_pushstring(luaI_typenames[-ttype(luaI_Address(o))]); | 183 | lua_pushstring(luaI_typenames[-ttype(luaI_Address(o))]); |
| 184 | lua_pushnumber(lua_tag(o)); | 184 | lua_pushnumber(lua_tag(o)); |
| 185 | } | 185 | } |
| @@ -212,29 +212,29 @@ static void luaI_assert (void) | |||
| 212 | static void luaI_setglobal (void) | 212 | static void luaI_setglobal (void) |
| 213 | { | 213 | { |
| 214 | lua_Object value = lua_getparam(2); | 214 | lua_Object value = lua_getparam(2); |
| 215 | luaL_arg_check(value != LUA_NOOBJECT, "setglobal", 2, NULL); | 215 | luaL_arg_check(value != LUA_NOOBJECT, 2, NULL); |
| 216 | lua_pushobject(value); | 216 | lua_pushobject(value); |
| 217 | lua_setglobal(luaL_check_string(1, "setglobal")); | 217 | lua_setglobal(luaL_check_string(1)); |
| 218 | lua_pushobject(value); /* return given value */ | 218 | lua_pushobject(value); /* return given value */ |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | static void luaI_rawsetglobal (void) | 221 | static void luaI_rawsetglobal (void) |
| 222 | { | 222 | { |
| 223 | lua_Object value = lua_getparam(2); | 223 | lua_Object value = lua_getparam(2); |
| 224 | luaL_arg_check(value != LUA_NOOBJECT, "rawsetglobal", 2, NULL); | 224 | luaL_arg_check(value != LUA_NOOBJECT, 2, NULL); |
| 225 | lua_pushobject(value); | 225 | lua_pushobject(value); |
| 226 | lua_rawsetglobal(luaL_check_string(1, "rawsetglobal")); | 226 | lua_rawsetglobal(luaL_check_string(1)); |
| 227 | lua_pushobject(value); /* return given value */ | 227 | lua_pushobject(value); /* return given value */ |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | static void luaI_getglobal (void) | 230 | static void luaI_getglobal (void) |
| 231 | { | 231 | { |
| 232 | lua_pushobject(lua_getglobal(luaL_check_string(1, "getglobal"))); | 232 | lua_pushobject(lua_getglobal(luaL_check_string(1))); |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | static void luaI_rawgetglobal (void) | 235 | static void luaI_rawgetglobal (void) |
| 236 | { | 236 | { |
| 237 | lua_pushobject(lua_rawgetglobal(luaL_check_string(1, "rawgetglobal"))); | 237 | lua_pushobject(lua_rawgetglobal(luaL_check_string(1))); |
| 238 | } | 238 | } |
| 239 | 239 | ||
| 240 | static void luatag (void) | 240 | static void luatag (void) |
| @@ -249,8 +249,8 @@ static void luaI_call (void) | |||
| 249 | lua_Object arg = lua_getparam(2); | 249 | lua_Object arg = lua_getparam(2); |
| 250 | lua_Object temp, params[MAXPARAMS]; | 250 | lua_Object temp, params[MAXPARAMS]; |
| 251 | int narg, i; | 251 | int narg, i; |
| 252 | luaL_arg_check(lua_isfunction(f), "call", 1, "function expected"); | 252 | luaL_arg_check(lua_isfunction(f), 1, "function expected"); |
| 253 | luaL_arg_check(lua_istable(arg), "call", 2, "table expected"); | 253 | luaL_arg_check(lua_istable(arg), 2, "table expected"); |
| 254 | /* narg = arg.n */ | 254 | /* narg = arg.n */ |
| 255 | lua_pushobject(arg); | 255 | lua_pushobject(arg); |
| 256 | lua_pushstring("n"); | 256 | lua_pushstring("n"); |
| @@ -280,9 +280,9 @@ static void luaI_call (void) | |||
| 280 | static void luaIl_settag (void) | 280 | static void luaIl_settag (void) |
| 281 | { | 281 | { |
| 282 | lua_Object o = lua_getparam(1); | 282 | lua_Object o = lua_getparam(1); |
| 283 | luaL_arg_check(o != LUA_NOOBJECT, "settag", 1, NULL); | 283 | luaL_arg_check(o != LUA_NOOBJECT, 1, NULL); |
| 284 | lua_pushobject(o); | 284 | lua_pushobject(o); |
| 285 | lua_settag(luaL_check_number(2, "settag")); | 285 | lua_settag(luaL_check_number(2)); |
| 286 | } | 286 | } |
| 287 | 287 | ||
| 288 | static void luaIl_newtag (void) | 288 | static void luaIl_newtag (void) |
| @@ -294,8 +294,8 @@ static void rawgettable (void) | |||
| 294 | { | 294 | { |
| 295 | lua_Object t = lua_getparam(1); | 295 | lua_Object t = lua_getparam(1); |
| 296 | lua_Object i = lua_getparam(2); | 296 | lua_Object i = lua_getparam(2); |
| 297 | luaL_arg_check(t != LUA_NOOBJECT, "rawgettable", 1, NULL); | 297 | luaL_arg_check(t != LUA_NOOBJECT, 1, NULL); |
| 298 | luaL_arg_check(i != LUA_NOOBJECT, "rawgettable", 2, NULL); | 298 | luaL_arg_check(i != LUA_NOOBJECT, 2, NULL); |
| 299 | lua_pushobject(t); | 299 | lua_pushobject(t); |
| 300 | lua_pushobject(i); | 300 | lua_pushobject(i); |
| 301 | lua_pushobject(lua_rawgettable()); | 301 | lua_pushobject(lua_rawgettable()); |
| @@ -307,7 +307,7 @@ static void rawsettable (void) | |||
| 307 | lua_Object i = lua_getparam(2); | 307 | lua_Object i = lua_getparam(2); |
| 308 | lua_Object v = lua_getparam(3); | 308 | lua_Object v = lua_getparam(3); |
| 309 | luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT, | 309 | luaL_arg_check(t != LUA_NOOBJECT && i != LUA_NOOBJECT && v != LUA_NOOBJECT, |
| 310 | "rawsettable", 0, NULL); | 310 | 0, NULL); |
| 311 | lua_pushobject(t); | 311 | lua_pushobject(t); |
| 312 | lua_pushobject(i); | 312 | lua_pushobject(i); |
| 313 | lua_pushobject(v); | 313 | lua_pushobject(v); |
| @@ -61,7 +61,7 @@ static void io_readfrom (void) | |||
| 61 | else if (lua_tag(f) == lua_tagio) | 61 | else if (lua_tag(f) == lua_tagio) |
| 62 | lua_infile = lua_getuserdata(f); | 62 | lua_infile = lua_getuserdata(f); |
| 63 | else { | 63 | else { |
| 64 | char *s = luaL_check_string(1, "readfrom"); | 64 | char *s = luaL_check_string(1); |
| 65 | FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); | 65 | FILE *fp = (*s == '|') ? popen(s+1, "r") : fopen(s, "r"); |
| 66 | if (fp) | 66 | if (fp) |
| 67 | lua_infile = fp; | 67 | lua_infile = fp; |
| @@ -82,7 +82,7 @@ static void io_writeto (void) | |||
| 82 | else if (lua_tag(f) == lua_tagio) | 82 | else if (lua_tag(f) == lua_tagio) |
| 83 | lua_outfile = lua_getuserdata(f); | 83 | lua_outfile = lua_getuserdata(f); |
| 84 | else { | 84 | else { |
| 85 | char *s = luaL_check_string(1, "writeto"); | 85 | char *s = luaL_check_string(1); |
| 86 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); | 86 | FILE *fp = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); |
| 87 | if (fp) | 87 | if (fp) |
| 88 | lua_outfile = fp; | 88 | lua_outfile = fp; |
| @@ -97,7 +97,7 @@ static void io_writeto (void) | |||
| 97 | 97 | ||
| 98 | static void io_appendto (void) | 98 | static void io_appendto (void) |
| 99 | { | 99 | { |
| 100 | char *s = luaL_check_string(1, "appendto"); | 100 | char *s = luaL_check_string(1); |
| 101 | FILE *fp = fopen (s, "a"); | 101 | FILE *fp = fopen (s, "a"); |
| 102 | if (fp != NULL) { | 102 | if (fp != NULL) { |
| 103 | lua_outfile = fp; | 103 | lua_outfile = fp; |
| @@ -113,7 +113,7 @@ static void io_appendto (void) | |||
| 113 | static void io_read (void) | 113 | static void io_read (void) |
| 114 | { | 114 | { |
| 115 | char *buff; | 115 | char *buff; |
| 116 | char *p = luaL_opt_string(1, "[^\n]*{\n}", "read"); | 116 | char *p = luaL_opt_string(1, "[^\n]*{\n}"); |
| 117 | int inskip = 0; /* to control {skips} */ | 117 | int inskip = 0; /* to control {skips} */ |
| 118 | int c = NEED_OTHER; | 118 | int c = NEED_OTHER; |
| 119 | luaI_emptybuff(); | 119 | luaI_emptybuff(); |
| @@ -164,7 +164,7 @@ static void io_write (void) | |||
| 164 | int arg = 1; | 164 | int arg = 1; |
| 165 | int status = 1; | 165 | int status = 1; |
| 166 | char *s; | 166 | char *s; |
| 167 | while ((s = luaL_opt_string(arg++, NULL, "write")) != NULL) | 167 | while ((s = luaL_opt_string(arg++, NULL)) != NULL) |
| 168 | status = status && (fputs(s, lua_outfile) != EOF); | 168 | status = status && (fputs(s, lua_outfile) != EOF); |
| 169 | pushresult(status); | 169 | pushresult(status); |
| 170 | } | 170 | } |
| @@ -172,20 +172,20 @@ static void io_write (void) | |||
| 172 | 172 | ||
| 173 | static void io_execute (void) | 173 | static void io_execute (void) |
| 174 | { | 174 | { |
| 175 | lua_pushnumber(system(luaL_check_string(1, "execute"))); | 175 | lua_pushnumber(system(luaL_check_string(1))); |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | 178 | ||
| 179 | static void io_remove (void) | 179 | static void io_remove (void) |
| 180 | { | 180 | { |
| 181 | pushresult(remove(luaL_check_string(1, "remove")) == 0); | 181 | pushresult(remove(luaL_check_string(1)) == 0); |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | 184 | ||
| 185 | static void io_rename (void) | 185 | static void io_rename (void) |
| 186 | { | 186 | { |
| 187 | pushresult(rename(luaL_check_string(1, "rename"), | 187 | pushresult(rename(luaL_check_string(1), |
| 188 | luaL_check_string(2, "rename")) == 0); | 188 | luaL_check_string(2)) == 0); |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | 191 | ||
| @@ -198,7 +198,7 @@ static void io_tmpname (void) | |||
| 198 | 198 | ||
| 199 | static void io_getenv (void) | 199 | static void io_getenv (void) |
| 200 | { | 200 | { |
| 201 | lua_pushstring(getenv(luaL_check_string(1, "getenv"))); /* if NULL push nil */ | 201 | lua_pushstring(getenv(luaL_check_string(1))); /* if NULL push nil */ |
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | 204 | ||
| @@ -206,7 +206,7 @@ static void io_date (void) | |||
| 206 | { | 206 | { |
| 207 | time_t t; | 207 | time_t t; |
| 208 | struct tm *tm; | 208 | struct tm *tm; |
| 209 | char *s = luaL_opt_string(1, "%c", "date"); | 209 | char *s = luaL_opt_string(1, "%c"); |
| 210 | char b[BUFSIZ]; | 210 | char b[BUFSIZ]; |
| 211 | time(&t); tm = localtime(&t); | 211 | time(&t); tm = localtime(&t); |
| 212 | if (strftime(b,sizeof(b),s,tm)) | 212 | if (strftime(b,sizeof(b),s,tm)) |
| @@ -282,8 +282,8 @@ static void errorfb (void) | |||
| 282 | static void getbyte (void) | 282 | static void getbyte (void) |
| 283 | { | 283 | { |
| 284 | lua_Object ud = lua_getparam(1); | 284 | lua_Object ud = lua_getparam(1); |
| 285 | int i = luaL_opt_number(2, -1, "getbyte"); | 285 | int i = luaL_opt_number(2, -1); |
| 286 | luaL_arg_check(lua_isuserdata(ud), "getbyte", 1, "userdata expected"); | 286 | luaL_arg_check(lua_isuserdata(ud), 1, "userdata expected"); |
| 287 | if (i == -1) | 287 | if (i == -1) |
| 288 | lua_pushnumber(lua_getbindatasize(ud)); | 288 | lua_pushnumber(lua_getbindatasize(ud)); |
| 289 | else { | 289 | else { |
| @@ -298,10 +298,10 @@ static void getbyte (void) | |||
| 298 | static void createuserdata (void) | 298 | static void createuserdata (void) |
| 299 | { | 299 | { |
| 300 | lua_Object t = lua_getparam(1); | 300 | lua_Object t = lua_getparam(1); |
| 301 | int tag = luaL_opt_number(2, 0, "createud"); | 301 | int tag = luaL_opt_number(2, 0); |
| 302 | int i; | 302 | int i; |
| 303 | luaI_emptybuff(); | 303 | luaI_emptybuff(); |
| 304 | luaL_arg_check(lua_istable(t), "createud", 1, "table expected"); | 304 | luaL_arg_check(lua_istable(t), 1, "table expected"); |
| 305 | for (i=0; ; i++) { | 305 | for (i=0; ; i++) { |
| 306 | lua_Object o; | 306 | lua_Object o; |
| 307 | lua_beginblock(); | 307 | lua_beginblock(); |
| @@ -312,8 +312,7 @@ static void createuserdata (void) | |||
| 312 | lua_endblock(); | 312 | lua_endblock(); |
| 313 | break; | 313 | break; |
| 314 | } | 314 | } |
| 315 | luaL_arg_check(lua_isnumber(o), "createud", 1, | 315 | luaL_arg_check(lua_isnumber(o), 1, "table values must be numbers"); |
| 316 | "table values must be numbers"); | ||
| 317 | luaI_addchar(lua_getnumber(o)); | 316 | luaI_addchar(lua_getnumber(o)); |
| 318 | lua_endblock(); | 317 | lua_endblock(); |
| 319 | } | 318 | } |
| @@ -1,4 +1,4 @@ | |||
| 1 | # $Id: makefile,v 1.31 1997/03/31 14:23:49 roberto Exp roberto $ | 1 | # $Id: makefile,v 1.32 1997/03/31 20:58:42 roberto Exp roberto $ |
| 2 | 2 | ||
| 3 | #configuration | 3 | #configuration |
| 4 | 4 | ||
| @@ -83,7 +83,7 @@ fallback.o: fallback.c auxlib.h lua.h luamem.h fallback.h opcode.h \ | |||
| 83 | func.o: func.c luadebug.h lua.h table.h tree.h types.h opcode.h func.h \ | 83 | func.o: func.c luadebug.h lua.h table.h tree.h types.h opcode.h func.h \ |
| 84 | luamem.h | 84 | luamem.h |
| 85 | hash.o: hash.c luamem.h opcode.h lua.h types.h tree.h func.h hash.h \ | 85 | hash.o: hash.c luamem.h opcode.h lua.h types.h tree.h func.h hash.h \ |
| 86 | table.h | 86 | table.h auxlib.h |
| 87 | inout.o: inout.c auxlib.h lua.h lex.h opcode.h types.h tree.h func.h \ | 87 | inout.o: inout.c auxlib.h lua.h lex.h opcode.h types.h tree.h func.h \ |
| 88 | inout.h table.h hash.h luamem.h fallback.h | 88 | inout.h table.h hash.h luamem.h fallback.h |
| 89 | iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.h | 89 | iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.h |
| @@ -93,12 +93,12 @@ lua.o: lua.c lua.h lualib.h | |||
| 93 | luamem.o: luamem.c luamem.h lua.h | 93 | luamem.o: luamem.c luamem.h lua.h |
| 94 | mathlib.o: mathlib.c lualib.h lua.h auxlib.h | 94 | mathlib.o: mathlib.c lualib.h lua.h auxlib.h |
| 95 | opcode.o: opcode.c luadebug.h lua.h luamem.h opcode.h types.h tree.h \ | 95 | opcode.o: opcode.c luadebug.h lua.h luamem.h opcode.h types.h tree.h \ |
| 96 | func.h hash.h inout.h table.h fallback.h undump.h | 96 | func.h hash.h inout.h table.h fallback.h undump.h auxlib.h |
| 97 | parser.o: parser.c luadebug.h lua.h luamem.h lex.h opcode.h types.h \ | 97 | parser.o: parser.c luadebug.h lua.h luamem.h lex.h opcode.h types.h \ |
| 98 | tree.h func.h hash.h inout.h table.h | 98 | tree.h func.h hash.h inout.h table.h |
| 99 | strlib.o: strlib.c lua.h auxlib.h lualib.h | 99 | strlib.o: strlib.c lua.h auxlib.h lualib.h |
| 100 | table.o: table.c luamem.h opcode.h lua.h types.h tree.h func.h hash.h \ | 100 | table.o: table.c luamem.h auxlib.h lua.h opcode.h types.h tree.h \ |
| 101 | table.h inout.h fallback.h luadebug.h | 101 | func.h hash.h table.h inout.h fallback.h luadebug.h |
| 102 | tree.o: tree.c luamem.h lua.h tree.h types.h lex.h hash.h opcode.h \ | 102 | tree.o: tree.c luamem.h lua.h tree.h types.h lex.h hash.h opcode.h \ |
| 103 | func.h table.h fallback.h | 103 | func.h table.h fallback.h |
| 104 | undump.o: undump.c opcode.h lua.h types.h tree.h func.h luamem.h \ | 104 | undump.o: undump.c opcode.h lua.h types.h tree.h func.h luamem.h \ |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Mathematics library to LUA | 3 | ** Mathematics library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.21 1997/03/21 18:37:28 roberto Exp roberto $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.22 1997/04/04 22:24:51 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <math.h> | 9 | #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 | |||
| 20 | 20 | ||
| 21 | static void math_abs (void) | 21 | static void math_abs (void) |
| 22 | { | 22 | { |
| 23 | double d = luaL_check_number(1, "abs"); | 23 | double d = luaL_check_number(1); |
| 24 | if (d < 0) d = -d; | 24 | if (d < 0) d = -d; |
| 25 | lua_pushnumber (d); | 25 | lua_pushnumber (d); |
| 26 | } | 26 | } |
| @@ -28,7 +28,7 @@ static void math_abs (void) | |||
| 28 | 28 | ||
| 29 | static void math_sin (void) | 29 | static void math_sin (void) |
| 30 | { | 30 | { |
| 31 | double d = luaL_check_number(1, "sin"); | 31 | double d = luaL_check_number(1); |
| 32 | lua_pushnumber (sin(TORAD(d))); | 32 | lua_pushnumber (sin(TORAD(d))); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -36,7 +36,7 @@ static void math_sin (void) | |||
| 36 | 36 | ||
| 37 | static void math_cos (void) | 37 | static void math_cos (void) |
| 38 | { | 38 | { |
| 39 | double d = luaL_check_number(1, "cos"); | 39 | double d = luaL_check_number(1); |
| 40 | lua_pushnumber (cos(TORAD(d))); | 40 | lua_pushnumber (cos(TORAD(d))); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| @@ -44,82 +44,82 @@ static void math_cos (void) | |||
| 44 | 44 | ||
| 45 | static void math_tan (void) | 45 | static void math_tan (void) |
| 46 | { | 46 | { |
| 47 | double d = luaL_check_number(1, "tan"); | 47 | double d = luaL_check_number(1); |
| 48 | lua_pushnumber (tan(TORAD(d))); | 48 | lua_pushnumber (tan(TORAD(d))); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | static void math_asin (void) | 52 | static void math_asin (void) |
| 53 | { | 53 | { |
| 54 | double d = luaL_check_number(1, "asin"); | 54 | double d = luaL_check_number(1); |
| 55 | lua_pushnumber (TODEGREE(asin(d))); | 55 | lua_pushnumber (TODEGREE(asin(d))); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | 58 | ||
| 59 | static void math_acos (void) | 59 | static void math_acos (void) |
| 60 | { | 60 | { |
| 61 | double d = luaL_check_number(1, "acos"); | 61 | double d = luaL_check_number(1); |
| 62 | lua_pushnumber (TODEGREE(acos(d))); | 62 | lua_pushnumber (TODEGREE(acos(d))); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | 65 | ||
| 66 | static void math_atan (void) | 66 | static void math_atan (void) |
| 67 | { | 67 | { |
| 68 | double d = luaL_check_number(1, "atan"); | 68 | double d = luaL_check_number(1); |
| 69 | lua_pushnumber (TODEGREE(atan(d))); | 69 | lua_pushnumber (TODEGREE(atan(d))); |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | 72 | ||
| 73 | static void math_atan2 (void) | 73 | static void math_atan2 (void) |
| 74 | { | 74 | { |
| 75 | double d1 = luaL_check_number(1, "atan2"); | 75 | double d1 = luaL_check_number(1); |
| 76 | double d2 = luaL_check_number(2, "atan2"); | 76 | double d2 = luaL_check_number(2); |
| 77 | lua_pushnumber (TODEGREE(atan2(d1, d2))); | 77 | lua_pushnumber (TODEGREE(atan2(d1, d2))); |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | static void math_ceil (void) | 81 | static void math_ceil (void) |
| 82 | { | 82 | { |
| 83 | double d = luaL_check_number(1, "ceil"); | 83 | double d = luaL_check_number(1); |
| 84 | lua_pushnumber (ceil(d)); | 84 | lua_pushnumber (ceil(d)); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | static void math_floor (void) | 88 | static void math_floor (void) |
| 89 | { | 89 | { |
| 90 | double d = luaL_check_number(1, "floor"); | 90 | double d = luaL_check_number(1); |
| 91 | lua_pushnumber (floor(d)); | 91 | lua_pushnumber (floor(d)); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | static void math_mod (void) | 94 | static void math_mod (void) |
| 95 | { | 95 | { |
| 96 | float x = luaL_check_number(1, "mod"); | 96 | float x = luaL_check_number(1); |
| 97 | float y = luaL_check_number(2, "mod"); | 97 | float y = luaL_check_number(2); |
| 98 | lua_pushnumber(fmod(x, y)); | 98 | lua_pushnumber(fmod(x, y)); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | 101 | ||
| 102 | static void math_sqrt (void) | 102 | static void math_sqrt (void) |
| 103 | { | 103 | { |
| 104 | double d = luaL_check_number(1, "sqrt"); | 104 | double d = luaL_check_number(1); |
| 105 | lua_pushnumber (sqrt(d)); | 105 | lua_pushnumber (sqrt(d)); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | 108 | ||
| 109 | static void math_pow (void) | 109 | static void math_pow (void) |
| 110 | { | 110 | { |
| 111 | double d1 = luaL_check_number(1, "exp"); | 111 | double d1 = luaL_check_number(1); |
| 112 | double d2 = luaL_check_number(2, "exp"); | 112 | double d2 = luaL_check_number(2); |
| 113 | lua_pushnumber(pow(d1,d2)); | 113 | lua_pushnumber(pow(d1,d2)); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | static void math_min (void) | 116 | static void math_min (void) |
| 117 | { | 117 | { |
| 118 | int i=1; | 118 | int i=1; |
| 119 | double dmin = luaL_check_number(i, "min"); | 119 | double dmin = luaL_check_number(i); |
| 120 | while (lua_getparam(++i) != LUA_NOOBJECT) | 120 | while (lua_getparam(++i) != LUA_NOOBJECT) |
| 121 | { | 121 | { |
| 122 | double d = luaL_check_number(i, "min"); | 122 | double d = luaL_check_number(i); |
| 123 | if (d < dmin) dmin = d; | 123 | if (d < dmin) dmin = d; |
| 124 | } | 124 | } |
| 125 | lua_pushnumber (dmin); | 125 | lua_pushnumber (dmin); |
| @@ -128,10 +128,10 @@ static void math_min (void) | |||
| 128 | static void math_max (void) | 128 | static void math_max (void) |
| 129 | { | 129 | { |
| 130 | int i=1; | 130 | int i=1; |
| 131 | double dmax = luaL_check_number(i, "max"); | 131 | double dmax = luaL_check_number(i); |
| 132 | while (lua_getparam(++i) != LUA_NOOBJECT) | 132 | while (lua_getparam(++i) != LUA_NOOBJECT) |
| 133 | { | 133 | { |
| 134 | double d = luaL_check_number(i, "max"); | 134 | double d = luaL_check_number(i); |
| 135 | if (d > dmax) dmax = d; | 135 | if (d > dmax) dmax = d; |
| 136 | } | 136 | } |
| 137 | lua_pushnumber (dmax); | 137 | lua_pushnumber (dmax); |
| @@ -139,33 +139,33 @@ static void math_max (void) | |||
| 139 | 139 | ||
| 140 | static void math_log (void) | 140 | static void math_log (void) |
| 141 | { | 141 | { |
| 142 | double d = luaL_check_number(1, "log"); | 142 | double d = luaL_check_number(1); |
| 143 | lua_pushnumber (log(d)); | 143 | lua_pushnumber (log(d)); |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | 146 | ||
| 147 | static void math_log10 (void) | 147 | static void math_log10 (void) |
| 148 | { | 148 | { |
| 149 | double d = luaL_check_number(1, "log10"); | 149 | double d = luaL_check_number(1); |
| 150 | lua_pushnumber (log10(d)); | 150 | lua_pushnumber (log10(d)); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | 153 | ||
| 154 | static void math_exp (void) | 154 | static void math_exp (void) |
| 155 | { | 155 | { |
| 156 | double d = luaL_check_number(1, "exp"); | 156 | double d = luaL_check_number(1); |
| 157 | lua_pushnumber (exp(d)); | 157 | lua_pushnumber (exp(d)); |
| 158 | } | 158 | } |
| 159 | 159 | ||
| 160 | static void math_deg (void) | 160 | static void math_deg (void) |
| 161 | { | 161 | { |
| 162 | float d = luaL_check_number(1, "deg"); | 162 | float d = luaL_check_number(1); |
| 163 | lua_pushnumber (d*180./PI); | 163 | lua_pushnumber (d*180./PI); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | static void math_rad (void) | 166 | static void math_rad (void) |
| 167 | { | 167 | { |
| 168 | float d = luaL_check_number(1, "rad"); | 168 | float d = luaL_check_number(1); |
| 169 | lua_pushnumber (d/180.*PI); | 169 | lua_pushnumber (d/180.*PI); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| @@ -176,7 +176,7 @@ static void math_random (void) | |||
| 176 | 176 | ||
| 177 | static void math_randomseed (void) | 177 | static void math_randomseed (void) |
| 178 | { | 178 | { |
| 179 | srand(luaL_check_number(1, "randomseed")); | 179 | srand(luaL_check_number(1)); |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | 182 | ||
| @@ -3,7 +3,7 @@ | |||
| 3 | ** String library to LUA | 3 | ** String library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_strlib="$Id: strlib.c,v 1.38 1997/03/26 22:23:15 roberto Exp roberto $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.39 1997/04/04 22:24:51 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -74,8 +74,8 @@ static void addstr (char *s) | |||
| 74 | */ | 74 | */ |
| 75 | static void str_tok (void) | 75 | static void str_tok (void) |
| 76 | { | 76 | { |
| 77 | char *s1 = luaL_check_string(1, "strtok"); | 77 | char *s1 = luaL_check_string(1); |
| 78 | char *del = luaL_check_string(2, "strtok"); | 78 | char *del = luaL_check_string(2); |
| 79 | lua_Object t = lua_createtable(); | 79 | lua_Object t = lua_createtable(); |
| 80 | int i = 1; | 80 | int i = 1; |
| 81 | /* As strtok changes s1, and s1 is "constant", make a copy of it */ | 81 | /* As strtok changes s1, and s1 is "constant", make a copy of it */ |
| @@ -97,7 +97,7 @@ static void str_tok (void) | |||
| 97 | */ | 97 | */ |
| 98 | static void str_len (void) | 98 | static void str_len (void) |
| 99 | { | 99 | { |
| 100 | lua_pushnumber(strlen(luaL_check_string(1, "strlen"))); | 100 | lua_pushnumber(strlen(luaL_check_string(1))); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | /* | 103 | /* |
| @@ -105,9 +105,9 @@ static void str_len (void) | |||
| 105 | */ | 105 | */ |
| 106 | static void str_sub (void) | 106 | static void str_sub (void) |
| 107 | { | 107 | { |
| 108 | char *s = luaL_check_string(1, "strsub"); | 108 | char *s = luaL_check_string(1); |
| 109 | long start = (long)luaL_check_number(2, "strsub"); | 109 | long start = (long)luaL_check_number(2); |
| 110 | long end = (long)luaL_opt_number(3, strlen(s), "strsub"); | 110 | long end = (long)luaL_opt_number(3, strlen(s)); |
| 111 | if (1 <= start && start <= end && end <= strlen(s)) { | 111 | if (1 <= start && start <= end && end <= strlen(s)) { |
| 112 | luaI_emptybuff(); | 112 | luaI_emptybuff(); |
| 113 | addnchar(s+start-1, end-start+1); | 113 | addnchar(s+start-1, end-start+1); |
| @@ -123,7 +123,7 @@ static void str_lower (void) | |||
| 123 | { | 123 | { |
| 124 | char *s; | 124 | char *s; |
| 125 | luaI_emptybuff(); | 125 | luaI_emptybuff(); |
| 126 | for (s = luaL_check_string(1, "strlower"); *s; s++) | 126 | for (s = luaL_check_string(1); *s; s++) |
| 127 | luaI_addchar(tolower((unsigned char)*s)); | 127 | luaI_addchar(tolower((unsigned char)*s)); |
| 128 | lua_pushstring(luaI_addchar(0)); | 128 | lua_pushstring(luaI_addchar(0)); |
| 129 | } | 129 | } |
| @@ -135,15 +135,15 @@ static void str_upper (void) | |||
| 135 | { | 135 | { |
| 136 | char *s; | 136 | char *s; |
| 137 | luaI_emptybuff(); | 137 | luaI_emptybuff(); |
| 138 | for (s = luaL_check_string(1, "strupper"); *s; s++) | 138 | for (s = luaL_check_string(1); *s; s++) |
| 139 | luaI_addchar(toupper((unsigned char)*s)); | 139 | luaI_addchar(toupper((unsigned char)*s)); |
| 140 | lua_pushstring(luaI_addchar(0)); | 140 | lua_pushstring(luaI_addchar(0)); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | static void str_rep (void) | 143 | static void str_rep (void) |
| 144 | { | 144 | { |
| 145 | char *s = luaL_check_string(1, "strrep"); | 145 | char *s = luaL_check_string(1); |
| 146 | int n = (int)luaL_check_number(2, "strrep"); | 146 | int n = (int)luaL_check_number(2); |
| 147 | luaI_emptybuff(); | 147 | luaI_emptybuff(); |
| 148 | while (n-- > 0) | 148 | while (n-- > 0) |
| 149 | addstr(s); | 149 | addstr(s); |
| @@ -155,9 +155,9 @@ static void str_rep (void) | |||
| 155 | */ | 155 | */ |
| 156 | static void str_ascii (void) | 156 | static void str_ascii (void) |
| 157 | { | 157 | { |
| 158 | char *s = luaL_check_string(1, "ascii"); | 158 | char *s = luaL_check_string(1); |
| 159 | long pos = (long)luaL_opt_number(2, 1, "ascii") - 1; | 159 | long pos = (long)luaL_opt_number(2, 1) - 1; |
| 160 | luaL_arg_check(0<=pos && pos<strlen(s), "ascii", 2, "out of range"); | 160 | luaL_arg_check(0<=pos && pos<strlen(s), 2, "out of range"); |
| 161 | lua_pushnumber((unsigned char)s[pos]); | 161 | lua_pushnumber((unsigned char)s[pos]); |
| 162 | } | 162 | } |
| 163 | 163 | ||
| @@ -364,10 +364,10 @@ static char *match (char *s, char *p, int level) | |||
| 364 | 364 | ||
| 365 | static void str_find (void) | 365 | static void str_find (void) |
| 366 | { | 366 | { |
| 367 | char *s = luaL_check_string(1, "strfind"); | 367 | char *s = luaL_check_string(1); |
| 368 | char *p = luaL_check_string(2, "strfind"); | 368 | char *p = luaL_check_string(2); |
| 369 | long init = (long)luaL_opt_number(3, 1, "strfind") - 1; | 369 | long init = (long)luaL_opt_number(3, 1) - 1; |
| 370 | luaL_arg_check(0 <= init && init <= strlen(s), "strfind", 3, "out of range"); | 370 | luaL_arg_check(0 <= init && init <= strlen(s), 3, "out of range"); |
| 371 | if (lua_getparam(4) != LUA_NOOBJECT || | 371 | if (lua_getparam(4) != LUA_NOOBJECT || |
| 372 | strpbrk(p, SPECIALS) == NULL) { /* no special caracters? */ | 372 | strpbrk(p, SPECIALS) == NULL) { /* no special caracters? */ |
| 373 | char *s2 = strstr(s+init, p); | 373 | char *s2 = strstr(s+init, p); |
| @@ -420,15 +420,15 @@ static void add_s (lua_Object newp) | |||
| 420 | addstr(lua_isstring(res) ? lua_getstring(res) : ""); | 420 | addstr(lua_isstring(res) ? lua_getstring(res) : ""); |
| 421 | lua_endblock(); | 421 | lua_endblock(); |
| 422 | } | 422 | } |
| 423 | else luaL_arg_check(0, "gsub", 3, NULL); | 423 | else luaL_arg_check(0, 3, NULL); |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | static void str_gsub (void) | 426 | static void str_gsub (void) |
| 427 | { | 427 | { |
| 428 | char *src = luaL_check_string(1, "gsub"); | 428 | char *src = luaL_check_string(1); |
| 429 | char *p = luaL_check_string(2, "gsub"); | 429 | char *p = luaL_check_string(2); |
| 430 | lua_Object newp = lua_getparam(3); | 430 | lua_Object newp = lua_getparam(3); |
| 431 | int max_s = (int)luaL_opt_number(4, strlen(src)+1, "gsub"); | 431 | int max_s = (int)luaL_opt_number(4, strlen(src)+1); |
| 432 | int anchor = (*p == '^') ? (p++, 1) : 0; | 432 | int anchor = (*p == '^') ? (p++, 1) : 0; |
| 433 | int n = 0; | 433 | int n = 0; |
| 434 | luaI_emptybuff(); | 434 | luaI_emptybuff(); |
| @@ -452,9 +452,9 @@ static void str_gsub (void) | |||
| 452 | 452 | ||
| 453 | static void str_set (void) | 453 | static void str_set (void) |
| 454 | { | 454 | { |
| 455 | char *item = luaL_check_string(1, "strset"); | 455 | char *item = luaL_check_string(1); |
| 456 | int i; | 456 | int i; |
| 457 | luaL_arg_check(*luaL_item_end(item) == 0, "strset", 1, "wrong format"); | 457 | luaL_arg_check(*luaL_item_end(item) == 0, 1, "wrong format"); |
| 458 | luaI_emptybuff(); | 458 | luaI_emptybuff(); |
| 459 | for (i=1; i<256; i++) /* 0 cannot be part of a set */ | 459 | for (i=1; i<256; i++) /* 0 cannot be part of a set */ |
| 460 | if (luaL_singlematch(i, item)) | 460 | if (luaL_singlematch(i, item)) |
| @@ -479,7 +479,7 @@ void luaI_addquoted (char *s) | |||
| 479 | static void str_format (void) | 479 | static void str_format (void) |
| 480 | { | 480 | { |
| 481 | int arg = 1; | 481 | int arg = 1; |
| 482 | char *strfrmt = luaL_check_string(arg++, "format"); | 482 | char *strfrmt = luaL_check_string(arg++); |
| 483 | luaI_emptybuff(); /* initialize */ | 483 | luaI_emptybuff(); /* initialize */ |
| 484 | while (*strfrmt) { | 484 | while (*strfrmt) { |
| 485 | if (*strfrmt != '%') | 485 | if (*strfrmt != '%') |
| @@ -498,20 +498,20 @@ static void str_format (void) | |||
| 498 | buff = openspace(1000); /* to store the formated value */ | 498 | buff = openspace(1000); /* to store the formated value */ |
| 499 | switch (*strfrmt++) { | 499 | switch (*strfrmt++) { |
| 500 | case 'q': | 500 | case 'q': |
| 501 | luaI_addquoted(luaL_check_string(arg++, "format")); | 501 | luaI_addquoted(luaL_check_string(arg++)); |
| 502 | continue; | 502 | continue; |
| 503 | case 's': { | 503 | case 's': { |
| 504 | char *s = luaL_check_string(arg++, "format"); | 504 | char *s = luaL_check_string(arg++); |
| 505 | buff = openspace(strlen(s)); | 505 | buff = openspace(strlen(s)); |
| 506 | sprintf(buff, form, s); | 506 | sprintf(buff, form, s); |
| 507 | break; | 507 | break; |
| 508 | } | 508 | } |
| 509 | case 'c': case 'd': case 'i': case 'o': | 509 | case 'c': case 'd': case 'i': case 'o': |
| 510 | case 'u': case 'x': case 'X': | 510 | case 'u': case 'x': case 'X': |
| 511 | sprintf(buff, form, (int)luaL_check_number(arg++, "format")); | 511 | sprintf(buff, form, (int)luaL_check_number(arg++)); |
| 512 | break; | 512 | break; |
| 513 | case 'e': case 'E': case 'f': case 'g': | 513 | case 'e': case 'E': case 'f': case 'g': |
| 514 | sprintf(buff, form, luaL_check_number(arg++, "format")); | 514 | sprintf(buff, form, luaL_check_number(arg++)); |
| 515 | break; | 515 | break; |
| 516 | default: /* also treat cases 'pnLlh' */ | 516 | default: /* also treat cases 'pnLlh' */ |
| 517 | lua_error("invalid format option in function `format'"); | 517 | lua_error("invalid format option in function `format'"); |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Module to control static tables | 3 | ** Module to control static tables |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_table="$Id: table.c,v 2.65 1997/03/31 14:17:09 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.66 1997/04/04 15:35:37 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include "luamem.h" | 8 | #include "luamem.h" |
| 9 | #include "auxlib.h" | 9 | #include "auxlib.h" |
| @@ -208,7 +208,7 @@ void luaI_nextvar (void) | |||
| 208 | if (lua_isnil(lua_getparam(1))) | 208 | if (lua_isnil(lua_getparam(1))) |
| 209 | next = 0; | 209 | next = 0; |
| 210 | else | 210 | else |
| 211 | next = luaI_findsymbolbyname(luaL_check_string(1, "nextvar")) + 1; | 211 | next = luaI_findsymbolbyname(luaL_check_string(1)) + 1; |
| 212 | while (next < lua_ntable && s_ttype(next) == LUA_T_NIL) | 212 | while (next < lua_ntable && s_ttype(next) == LUA_T_NIL) |
| 213 | next++; | 213 | next++; |
| 214 | if (next < lua_ntable) { | 214 | if (next < lua_ntable) { |
