diff options
-rw-r--r-- | loslib.c | 18 | ||||
-rw-r--r-- | luaconf.h | 14 |
2 files changed, 27 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp roberto $ | 2 | ** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp roberto $ |
3 | ** Standard Operating System library | 3 | ** Standard Operating System library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -148,15 +148,25 @@ static int os_date (lua_State *L) { | |||
148 | else { | 148 | else { |
149 | char cc[3]; | 149 | char cc[3]; |
150 | luaL_Buffer b; | 150 | luaL_Buffer b; |
151 | cc[0] = '%'; cc[2] = '\0'; | 151 | cc[0] = '%'; |
152 | luaL_buffinit(L, &b); | 152 | luaL_buffinit(L, &b); |
153 | for (; *s; s++) { | 153 | for (; *s; s++) { |
154 | if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ | 154 | if (*s != '%') /* no conversion specifier? */ |
155 | luaL_addchar(&b, *s); | 155 | luaL_addchar(&b, *s); |
156 | else { | 156 | else { |
157 | size_t reslen; | 157 | size_t reslen; |
158 | int i = 1; | ||
158 | char buff[200]; /* should be big enough for any conversion result */ | 159 | char buff[200]; /* should be big enough for any conversion result */ |
159 | cc[1] = *(++s); | 160 | if (*(++s) != '\0' && strchr(LUA_STRFTIMEPREFIX, *s)) |
161 | cc[i++] = *(s++); | ||
162 | if (*s != '\0' && strchr(LUA_STRFTIMEOPTIONS, *s)) | ||
163 | cc[i++] = *s; | ||
164 | else { | ||
165 | const char *msg = lua_pushfstring(L, | ||
166 | "invalid conversion specifier '%%%c'", *s); | ||
167 | return luaL_argerror(L, 1, msg); | ||
168 | } | ||
169 | cc[i] = '\0'; | ||
160 | reslen = strftime(buff, sizeof(buff), cc, stm); | 170 | reslen = strftime(buff, sizeof(buff), cc, stm); |
161 | luaL_addlstring(&b, buff, reslen); | 171 | luaL_addlstring(&b, buff, reslen); |
162 | } | 172 | } |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: luaconf.h,v 1.86 2006/09/18 14:03:18 roberto Exp roberto $ | 2 | ** $Id: luaconf.h,v 1.87 2007/02/07 17:46:20 roberto Exp roberto $ |
3 | ** Configuration file for Lua | 3 | ** Configuration file for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -658,6 +658,18 @@ union luai_Cast { double l_d; long l_l; }; | |||
658 | 658 | ||
659 | 659 | ||
660 | /* | 660 | /* |
661 | @@ LUA_STRFTIMEOPTIONS is the list of valid conversion specifier | ||
662 | @* characters for the 'strftime' function; | ||
663 | @@ LUA_STRFTIMEPREFIX is the list of valid modifiers for | ||
664 | @* that function. | ||
665 | ** CHANGE them if you want to use non-ansi options specific to your system. | ||
666 | */ | ||
667 | #define LUA_STRFTIMEOPTIONS "aAbBcdHIjmMpSUwWxXyYz%" | ||
668 | #define LUA_STRFTIMEPREFIX "" | ||
669 | |||
670 | |||
671 | |||
672 | /* | ||
661 | @@ lua_popen spawns a new process connected to the current one through | 673 | @@ lua_popen spawns a new process connected to the current one through |
662 | @* the file streams. | 674 | @* the file streams. |
663 | ** CHANGE it if you have a way to implement it in your system. | 675 | ** CHANGE it if you have a way to implement it in your system. |