aboutsummaryrefslogtreecommitdiff
path: root/iolib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-01 16:32:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-07-01 16:32:41 -0300
commit7820a47184c0079677c5c430125f0541af05c8b6 (patch)
tree10ffcef30c0fa0a172056529b90176133220159d /iolib.c
parent88b185ada15b76d6bfe8bb5e2d38935cf32e618a (diff)
downloadlua-7820a47184c0079677c5c430125f0541af05c8b6.tar.gz
lua-7820a47184c0079677c5c430125f0541af05c8b6.tar.bz2
lua-7820a47184c0079677c5c430125f0541af05c8b6.zip
LOCALE support
Diffstat (limited to 'iolib.c')
-rw-r--r--iolib.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/iolib.c b/iolib.c
index e518df1b..dd957638 100644
--- a/iolib.c
+++ b/iolib.c
@@ -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
239static 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
238static void io_exit (void) 249static void io_exit (void)
@@ -300,6 +311,7 @@ static void errorfb (void)
300 311
301 312
302static struct luaL_reg iolib[] = { 313static 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},