diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-16 13:53:57 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-12-16 13:53:57 -0200 |
| commit | fad57bfa008523c3568b613989a6a3f87f3cb83b (patch) | |
| tree | ca47286ada599e45f4445e16d6a410833d4735e8 /strlib.c | |
| parent | 891cab8a31ec73dddb5aa896abedbac53b4c16f8 (diff) | |
| download | lua-fad57bfa008523c3568b613989a6a3f87f3cb83b.tar.gz lua-fad57bfa008523c3568b613989a6a3f87f3cb83b.tar.bz2 lua-fad57bfa008523c3568b613989a6a3f87f3cb83b.zip | |
new constant LUA_NOOBJECT.
'lua_error' never returns
Diffstat (limited to 'strlib.c')
| -rw-r--r-- | strlib.c | 16 |
1 files changed, 8 insertions, 8 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.5 1994/11/16 17:38:08 roberto Stab $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.6 1994/12/13 15:54:21 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <ctype.h> | 9 | #include <ctype.h> |
| @@ -23,7 +23,7 @@ static void str_find (void) | |||
| 23 | lua_Object o1 = lua_getparam (1); | 23 | lua_Object o1 = lua_getparam (1); |
| 24 | lua_Object o2 = lua_getparam (2); | 24 | lua_Object o2 = lua_getparam (2); |
| 25 | if (!lua_isstring(o1) || !lua_isstring(o2)) | 25 | if (!lua_isstring(o1) || !lua_isstring(o2)) |
| 26 | { lua_error ("incorrect arguments to function `strfind'"); return; } | 26 | lua_error ("incorrect arguments to function `strfind'"); |
| 27 | s1 = lua_getstring(o1); | 27 | s1 = lua_getstring(o1); |
| 28 | s2 = lua_getstring(o2); | 28 | s2 = lua_getstring(o2); |
| 29 | f = strstr(s1,s2); | 29 | f = strstr(s1,s2); |
| @@ -42,7 +42,7 @@ static void str_len (void) | |||
| 42 | { | 42 | { |
| 43 | lua_Object o = lua_getparam (1); | 43 | lua_Object o = lua_getparam (1); |
| 44 | if (!lua_isstring(o)) | 44 | if (!lua_isstring(o)) |
| 45 | { lua_error ("incorrect arguments to function `strlen'"); return; } | 45 | lua_error ("incorrect arguments to function `strlen'"); |
| 46 | lua_pushnumber(strlen(lua_getstring(o))); | 46 | lua_pushnumber(strlen(lua_getstring(o))); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| @@ -60,9 +60,9 @@ static void str_sub (void) | |||
| 60 | lua_Object o2 = lua_getparam (2); | 60 | lua_Object o2 = lua_getparam (2); |
| 61 | lua_Object o3 = lua_getparam (3); | 61 | lua_Object o3 = lua_getparam (3); |
| 62 | if (!lua_isstring(o1) || !lua_isnumber(o2)) | 62 | if (!lua_isstring(o1) || !lua_isnumber(o2)) |
| 63 | { lua_error ("incorrect arguments to function `strsub'"); return; } | 63 | lua_error ("incorrect arguments to function `strsub'"); |
| 64 | if (o3 != NULL && !lua_isnumber(o3)) | 64 | if (o3 != LUA_NOOBJECT && !lua_isnumber(o3)) |
| 65 | { lua_error ("incorrect third argument to function `strsub'"); return; } | 65 | lua_error ("incorrect third argument to function `strsub'"); |
| 66 | s = lua_copystring(o1); | 66 | s = lua_copystring(o1); |
| 67 | start = lua_getnumber (o2); | 67 | start = lua_getnumber (o2); |
| 68 | end = o3 == NULL ? strlen(s) : lua_getnumber (o3); | 68 | end = o3 == NULL ? strlen(s) : lua_getnumber (o3); |
| @@ -86,7 +86,7 @@ static void str_lower (void) | |||
| 86 | char *s, *c; | 86 | char *s, *c; |
| 87 | lua_Object o = lua_getparam (1); | 87 | lua_Object o = lua_getparam (1); |
| 88 | if (!lua_isstring(o)) | 88 | if (!lua_isstring(o)) |
| 89 | { lua_error ("incorrect arguments to function `strlower'"); return; } | 89 | lua_error ("incorrect arguments to function `strlower'"); |
| 90 | c = s = strdup(lua_getstring(o)); | 90 | c = s = strdup(lua_getstring(o)); |
| 91 | while (*c != 0) | 91 | while (*c != 0) |
| 92 | { | 92 | { |
| @@ -108,7 +108,7 @@ static void str_upper (void) | |||
| 108 | char *s, *c; | 108 | char *s, *c; |
| 109 | lua_Object o = lua_getparam (1); | 109 | lua_Object o = lua_getparam (1); |
| 110 | if (!lua_isstring(o)) | 110 | if (!lua_isstring(o)) |
| 111 | { lua_error ("incorrect arguments to function `strlower'"); return; } | 111 | lua_error ("incorrect arguments to function `strlower'"); |
| 112 | c = s = strdup(lua_getstring(o)); | 112 | c = s = strdup(lua_getstring(o)); |
| 113 | while (*c != 0) | 113 | while (*c != 0) |
| 114 | { | 114 | { |
