diff options
Diffstat (limited to 'iolib.c')
-rw-r--r-- | iolib.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -4,6 +4,7 @@ | |||
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | #include <errno.h> | 5 | #include <errno.h> |
6 | 6 | ||
7 | #include "lualoc.h" | ||
7 | #include "lua.h" | 8 | #include "lua.h" |
8 | #include "auxlib.h" | 9 | #include "auxlib.h" |
9 | #include "luadebug.h" | 10 | #include "luadebug.h" |
@@ -28,7 +29,7 @@ static void pushresult (int i) | |||
28 | lua_pushuserdata(NULL); | 29 | lua_pushuserdata(NULL); |
29 | else { | 30 | else { |
30 | lua_pushnil(); | 31 | lua_pushnil(); |
31 | #ifndef NOSTRERROR | 32 | #ifndef OLD_ANSI |
32 | lua_pushstring(strerror(errno)); | 33 | lua_pushstring(strerror(errno)); |
33 | #else | 34 | #else |
34 | lua_pushstring("O.S. unable to define the error"); | 35 | lua_pushstring("O.S. unable to define the error"); |
@@ -233,6 +234,16 @@ static void io_date (void) | |||
233 | else | 234 | else |
234 | lua_error("invalid `date' format"); | 235 | lua_error("invalid `date' format"); |
235 | } | 236 | } |
237 | |||
238 | |||
239 | static void setloc (void) | ||
240 | { | ||
241 | static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, | ||
242 | LC_TIME}; | ||
243 | int op = (int)luaL_opt_number(2, 0); | ||
244 | luaL_arg_check(0 <= op && op <= 5, 2, "invalid option"); | ||
245 | lua_pushstring(setlocale(cat[op], luaL_check_string(1))); | ||
246 | } | ||
236 | 247 | ||
237 | 248 | ||
238 | static void io_exit (void) | 249 | static void io_exit (void) |
@@ -300,6 +311,7 @@ static void errorfb (void) | |||
300 | 311 | ||
301 | 312 | ||
302 | static struct luaL_reg iolib[] = { | 313 | static struct luaL_reg iolib[] = { |
314 | {"setlocale", setloc}, | ||
303 | {"readfrom", io_readfrom}, | 315 | {"readfrom", io_readfrom}, |
304 | {"writeto", io_writeto}, | 316 | {"writeto", io_writeto}, |
305 | {"appendto", io_appendto}, | 317 | {"appendto", io_appendto}, |