diff options
| author | Mike Pall <mike> | 2025-11-27 17:45:17 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2025-11-27 17:45:17 +0100 |
| commit | f80b349d5490aa289b2925d297f3f3c618977570 (patch) | |
| tree | 8d8fb0d2beb3e863592139d603ada63e5aa6ce77 /src/lib_os.c | |
| parent | 3215838aa744d148e79a8ea0bd7c014e984302cb (diff) | |
| download | luajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.gz luajit-f80b349d5490aa289b2925d297f3f3c618977570.tar.bz2 luajit-f80b349d5490aa289b2925d297f3f3c618977570.zip | |
Unify Lua number to FFI integer conversions.
Phew. #1411
Diffstat (limited to 'src/lib_os.c')
| -rw-r--r-- | src/lib_os.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib_os.c b/src/lib_os.c index ae3fc857..fffc923e 100644 --- a/src/lib_os.c +++ b/src/lib_os.c | |||
| @@ -171,7 +171,8 @@ static int getfield(lua_State *L, const char *key, int d) | |||
| 171 | LJLIB_CF(os_date) | 171 | LJLIB_CF(os_date) |
| 172 | { | 172 | { |
| 173 | const char *s = luaL_optstring(L, 1, "%c"); | 173 | const char *s = luaL_optstring(L, 1, "%c"); |
| 174 | time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); | 174 | time_t t = lua_isnoneornil(L, 2) ? time(NULL) : |
| 175 | lj_num2int_type(luaL_checknumber(L, 2), time_t); | ||
| 175 | struct tm *stm; | 176 | struct tm *stm; |
| 176 | #if LJ_TARGET_POSIX | 177 | #if LJ_TARGET_POSIX |
| 177 | struct tm rtm; | 178 | struct tm rtm; |
| @@ -253,8 +254,9 @@ LJLIB_CF(os_time) | |||
| 253 | 254 | ||
| 254 | LJLIB_CF(os_difftime) | 255 | LJLIB_CF(os_difftime) |
| 255 | { | 256 | { |
| 256 | lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), | 257 | lua_pushnumber(L, |
| 257 | (time_t)(luaL_optnumber(L, 2, (lua_Number)0)))); | 258 | difftime(lj_num2int_type(luaL_checknumber(L, 1), time_t), |
| 259 | lj_num2int_type(luaL_optnumber(L, 2, (lua_Number)0), time_t))); | ||
| 258 | return 1; | 260 | return 1; |
| 259 | } | 261 | } |
| 260 | 262 | ||
