diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-04 19:24:51 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-04-04 19:24:51 -0300 |
commit | 42fa305649199712aad1c96beadb944b01277e3f (patch) | |
tree | d20afcf78aebc8b7fad91ce4e3b9061c2a29b000 /strlib.c | |
parent | 9319735744404831f7153653930d56826a4d2f6a (diff) | |
download | lua-42fa305649199712aad1c96beadb944b01277e3f.tar.gz lua-42fa305649199712aad1c96beadb944b01277e3f.tar.bz2 lua-42fa305649199712aad1c96beadb944b01277e3f.zip |
better error messages;
better names for some API functions.
Diffstat (limited to 'strlib.c')
-rw-r--r-- | strlib.c | 22 |
1 files changed, 11 insertions, 11 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.37 1997/03/18 15:30:50 roberto Exp roberto $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.38 1997/03/26 22:23:15 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -84,7 +84,7 @@ static void str_tok (void) | |||
84 | lua_pushobject(t); | 84 | lua_pushobject(t); |
85 | lua_pushnumber(i++); | 85 | lua_pushnumber(i++); |
86 | lua_pushstring(s1); | 86 | lua_pushstring(s1); |
87 | lua_storesubscript(); | 87 | lua_settable(); |
88 | s1 = NULL; /* prepare for next strtok */ | 88 | s1 = NULL; /* prepare for next strtok */ |
89 | } | 89 | } |
90 | lua_pushobject(t); | 90 | lua_pushobject(t); |
@@ -121,10 +121,10 @@ static void str_sub (void) | |||
121 | */ | 121 | */ |
122 | static void str_lower (void) | 122 | static void str_lower (void) |
123 | { | 123 | { |
124 | char *s = luaL_check_string(1, "strlower"); | 124 | char *s; |
125 | luaI_emptybuff(); | 125 | luaI_emptybuff(); |
126 | while (*s) | 126 | for (s = luaL_check_string(1, "strlower"); *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 | } |
130 | 130 | ||
@@ -133,10 +133,10 @@ static void str_lower (void) | |||
133 | */ | 133 | */ |
134 | static void str_upper (void) | 134 | static void str_upper (void) |
135 | { | 135 | { |
136 | char *s = luaL_check_string(1, "strupper"); | 136 | char *s; |
137 | luaI_emptybuff(); | 137 | luaI_emptybuff(); |
138 | while (*s) | 138 | for (s = luaL_check_string(1, "strupper"); *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 | ||
@@ -177,11 +177,11 @@ char *luaL_item_end (char *p) | |||
177 | switch (*p++) { | 177 | switch (*p++) { |
178 | case '\0': return p-1; | 178 | case '\0': return p-1; |
179 | case ESC: | 179 | case ESC: |
180 | if (*p == 0) lua_error("incorrect pattern"); | 180 | if (*p == 0) luaL_verror("incorrect pattern (ends with `%c')", ESC); |
181 | return p+1; | 181 | return p+1; |
182 | case '[': { | 182 | case '[': { |
183 | char *end = bracket_end(p); | 183 | char *end = bracket_end(p); |
184 | if (end == NULL) lua_error("incorrect pattern"); | 184 | if (end == NULL) lua_error("incorrect pattern (missing `]')"); |
185 | return end+1; | 185 | return end+1; |
186 | } | 186 | } |
187 | default: | 187 | default: |
@@ -492,7 +492,7 @@ static void str_format (void) | |||
492 | char *initf = strfrmt-1; /* -1 to include % */ | 492 | char *initf = strfrmt-1; /* -1 to include % */ |
493 | strfrmt = match(strfrmt, "[-+ #]*(%d*)%.?(%d*)", 0); | 493 | strfrmt = match(strfrmt, "[-+ #]*(%d*)%.?(%d*)", 0); |
494 | if (capture[0].len > 3 || capture[1].len > 3) /* < 1000? */ | 494 | if (capture[0].len > 3 || capture[1].len > 3) /* < 1000? */ |
495 | lua_error("invalid format (width/precision too long)"); | 495 | lua_error("invalid format (width or precision too long)"); |
496 | strncpy(form, initf, strfrmt-initf+1); /* +1 to include convertion */ | 496 | strncpy(form, initf, strfrmt-initf+1); /* +1 to include convertion */ |
497 | form[strfrmt-initf+1] = 0; | 497 | form[strfrmt-initf+1] = 0; |
498 | buff = openspace(1000); /* to store the formated value */ | 498 | buff = openspace(1000); /* to store the formated value */ |