diff options
Diffstat (limited to '')
| -rw-r--r-- | strlib.c | 9 |
1 files changed, 6 insertions, 3 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.40 1997/04/06 14:08:08 roberto Exp roberto $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.41 1997/04/06 14:17:06 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -106,9 +106,12 @@ static void str_len (void) | |||
| 106 | static void str_sub (void) | 106 | static void str_sub (void) |
| 107 | { | 107 | { |
| 108 | char *s = luaL_check_string(1); | 108 | char *s = luaL_check_string(1); |
| 109 | long l = strlen(s); | ||
| 109 | long start = (long)luaL_check_number(2); | 110 | long start = (long)luaL_check_number(2); |
| 110 | long end = (long)luaL_opt_number(3, strlen(s)); | 111 | long end = (long)luaL_opt_number(3, -1); |
| 111 | if (1 <= start && start <= end && end <= strlen(s)) { | 112 | if (start < 0) start = l+start+1; |
| 113 | if (end < 0) end = l+end+1; | ||
| 114 | if (1 <= start && start <= end && end <= l) { | ||
| 112 | luaI_emptybuff(); | 115 | luaI_emptybuff(); |
| 113 | addnchar(s+start-1, end-start+1); | 116 | addnchar(s+start-1, end-start+1); |
| 114 | lua_pushstring(luaI_addchar(0)); | 117 | lua_pushstring(luaI_addchar(0)); |
