# # # patch "lua/lbaselib.cc" # from [d2506c4c2c947a39aa54b6b471ca3323cd5615a6] # to [c1ee2d0ced8208b8bbcd92677879ca218f57bea3] # # patch "lua/loslib.cc" # from [27c084b47c695fa161441780ef6b25fc06772a00] # to [81372f1a7d5ff1354481dba955674ad3a0335657] # ============================================================ --- lua/lbaselib.cc d2506c4c2c947a39aa54b6b471ca3323cd5615a6 +++ lua/lbaselib.cc c1ee2d0ced8208b8bbcd92677879ca218f57bea3 @@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State } -static void getfunc (lua_State *L) { +static void getfunc (lua_State *L, int opt) { if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); else { lua_Debug ar; - int level = luaL_optint(L, 1, 1); + int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); if (lua_getstack(L, level, &ar) == 0) luaL_argerror(L, 1, "invalid level"); @@ -131,7 +131,7 @@ static int luaB_getfenv (lua_State *L) { static int luaB_getfenv (lua_State *L) { - getfunc(L); + getfunc(L, 1); if (lua_iscfunction(L, -1)) /* is a C function? */ lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ else @@ -142,7 +142,7 @@ static int luaB_setfenv (lua_State *L) { static int luaB_setfenv (lua_State *L) { luaL_checktype(L, 2, LUA_TTABLE); - getfunc(L); + getfunc(L, 0); lua_pushvalue(L, 2); if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { /* change environment of current thread */ ============================================================ --- lua/loslib.cc 27c084b47c695fa161441780ef6b25fc06772a00 +++ lua/loslib.cc 81372f1a7d5ff1354481dba955674ad3a0335657 @@ -145,12 +145,23 @@ static int os_date (lua_State *L) { setfield(L, "yday", stm->tm_yday+1); setboolfield(L, "isdst", stm->tm_isdst); } - else { - char b[256]; - if (strftime(b, sizeof(b), s, stm)) - lua_pushstring(L, b); - else - return luaL_error(L, LUA_QL("date") " format too long"); + else { + char cc[3]; + luaL_Buffer b; + cc[0] = '%'; cc[2] = '\0'; + luaL_buffinit(L, &b); + for (; *s; s++) { + if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */ + luaL_addchar(&b, *s); + else { + size_t reslen; + char buff[200]; /* should be big enough for any conversion result */ + cc[1] = *(++s); + reslen = strftime(buff, sizeof(buff), cc, stm); + luaL_addlstring(&b, buff, reslen); + } + } + luaL_pushresult(&b); } return 1; }