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 /strlib.c | |
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).
Diffstat (limited to 'strlib.c')
-rw-r--r-- | strlib.c | 58 |
1 files changed, 29 insertions, 29 deletions
@@ -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'"); |