2
0
Roberto Ierusalimschy 28 жил өмнө
parent
commit
7820a47184
5 өөрчлөгдсөн 53 нэмэгдсэн , 45 устгасан
  1. 13 1
      iolib.c
  2. 20 34
      lex.c
  3. 3 1
      lua.c
  4. 14 7
      makefile
  5. 3 2
      opcode.c

+ 13 - 1
iolib.c

@@ -4,6 +4,7 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#include "lualoc.h"
 #include "lua.h"
 #include "auxlib.h"
 #include "luadebug.h"
@@ -28,7 +29,7 @@ static void pushresult (int i)
     lua_pushuserdata(NULL);
   else {
     lua_pushnil();
-#ifndef NOSTRERROR
+#ifndef OLD_ANSI
     lua_pushstring(strerror(errno));
 #else
     lua_pushstring("O.S. unable to define the error");
@@ -233,6 +234,16 @@ static void io_date (void)
   else
     lua_error("invalid `date' format");
 }
+
+
+static void setloc (void)
+{
+  static int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC,
+                      LC_TIME};
+  int op = (int)luaL_opt_number(2, 0);
+  luaL_arg_check(0 <= op && op <= 5, 2, "invalid option");
+  lua_pushstring(setlocale(cat[op], luaL_check_string(1)));
+}
  
 
 static void io_exit (void)
@@ -300,6 +311,7 @@ static void errorfb (void)
 
 
 static struct luaL_reg iolib[] = {
+{"setlocale", setloc},
 {"readfrom", io_readfrom},
 {"writeto",  io_writeto},
 {"appendto", io_appendto},

+ 20 - 34
lex.c

@@ -1,4 +1,4 @@
-char *rcs_lex = "$Id: lex.c,v 3.4 1997/06/11 18:56:02 roberto Exp roberto $";
+char *rcs_lex = "$Id: lex.c,v 3.5 1997/06/16 16:50:22 roberto Exp roberto $";
 
 
 #include <ctype.h>
@@ -278,11 +278,9 @@ int luaY_lex (void)
   if (lua_debug)
     luaI_codedebugline(linelasttoken);
   linelasttoken = lua_linenumber;
-  while (1)
-  {
+  while (1) {
     int tokensize = 0;
-    switch (current)
-    {
+    switch (current) {
       case '\n':
         inclinenumber();
         linelasttoken = lua_linenumber;
@@ -365,33 +363,6 @@ int luaY_lex (void)
         return STRING;
       }
 
-      case 'a': case 'b': case 'c': case 'd': case 'e':
-      case 'f': case 'g': case 'h': case 'i': case 'j':
-      case 'k': case 'l': case 'm': case 'n': case 'o':
-      case 'p': case 'q': case 'r': case 's': case 't':
-      case 'u': case 'v': case 'w': case 'x': case 'y':
-      case 'z':
-      case 'A': case 'B': case 'C': case 'D': case 'E':
-      case 'F': case 'G': case 'H': case 'I': case 'J':
-      case 'K': case 'L': case 'M': case 'N': case 'O':
-      case 'P': case 'Q': case 'R': case 'S': case 'T':
-      case 'U': case 'V': case 'W': case 'X': case 'Y':
-      case 'Z':
-      case '_':
-      {
-        TaggedString *ts;
-        do {
-          save_and_next();
-        } while (isalnum((unsigned char)current) || current == '_');
-        save(0);
-        ts = lua_createstring(yytext);
-        if (ts->marked > 2)
-          return ts->marked;  /* reserved word */
-        luaY_lval.pTStr = ts;
-        ts->marked = 2;  /* avoid GC */
-        return NAME;
-      }
-
       case '.':
         save_and_next();
         if (current == '.')
@@ -462,8 +433,23 @@ int luaY_lex (void)
         return 0;
 
       default:
-        save_and_next();
-        return yytext[0];
+        if (current != '_' && !isalpha((unsigned char)current)) {
+          save_and_next();
+          return yytext[0];
+        }
+        else {  /* identifier or reserved word */
+          TaggedString *ts;
+          do {
+            save_and_next();
+          } while (isalnum((unsigned char)current) || current == '_');
+          save(0);
+          ts = lua_createstring(yytext);
+          if (ts->marked > 2)
+            return ts->marked;  /* reserved word */
+          luaY_lval.pTStr = ts;
+          ts->marked = 2;  /* avoid GC */
+          return NAME;
+        }
     }
   }
 }

+ 3 - 1
lua.c

@@ -3,11 +3,12 @@
 ** Linguagem para Usuarios de Aplicacao
 */
 
-char *rcs_lua="$Id: lua.c,v 1.17 1997/06/18 21:20:45 roberto Exp roberto $";
+char *rcs_lua="$Id: lua.c,v 1.18 1997/06/19 18:55:40 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
 
+#include "lualoc.h"
 #include "lua.h"
 #include "auxlib.h"
 #include "lualib.h"
@@ -107,6 +108,7 @@ int main (int argc, char *argv[])
 {
   int i;
   int result = 0;
+  setlocale(LC_ALL, "");
   iolib_open ();
   strlib_open ();
   mathlib_open ();

+ 14 - 7
makefile

@@ -1,18 +1,25 @@
-# $Id: makefile,v 1.35 1997/06/16 16:50:22 roberto Exp roberto $
+# $Id: makefile,v 1.36 1997/06/23 18:27:53 roberto Exp roberto $
 
 #configuration
 
 # define (undefine) POPEN if your system (does not) support piped I/O
+#
 # define (undefine) _POSIX_SOURCE if your system is (not) POSIX compliant
-#define (undefine) NOSTRERROR if your system does NOT have function "strerror"
-# (although this is ANSI, SunOS does not comply; so, add "-DNOSTRERROR" on SunOS)
+#
+# define (undefine) OLD_ANSI if your system does NOT have some new ANSI
+#   facilities ("strerror" and "locale.h"). Although they are ANSI,
+#   SunOS does not comply; so, add "-DOLD_ANSI" on SunOS
+#
 # define LUA_COMPAT2_5=0 if yous system does not need to be compatible with
 # version 2.5 (or older)
+
 CONFIG = -DPOPEN -D_POSIX_SOURCE
+
+
 # Compilation parameters
 CC = gcc
 CWARNS = -Wall -Wmissing-prototypes -Wshadow -pedantic -Wpointer-arith -Wcast-align -Waggregate-return
-CFLAGS = $(CONFIG) $(CWARNS) -ansi -O2 -fomit-frame-pointer
+CFLAGS = $(CONFIG) $(CWARNS) -ansi -O2
 
 #CC = acc
 #CFLAGS = -fast -I/usr/5include
@@ -89,14 +96,14 @@ hash.o: hash.c luamem.h opcode.h lua.h types.h tree.h func.h hash.h \
  table.h auxlib.h
 inout.o: inout.c auxlib.h lua.h fallback.h opcode.h types.h tree.h \
  func.h hash.h inout.h lex.h zio.h luamem.h table.h undump.h
-iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.h
+iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.h lualoc.h
 lex.o: lex.c auxlib.h lua.h luamem.h tree.h types.h table.h opcode.h \
  func.h lex.h zio.h inout.h luadebug.h parser.h
-lua.o: lua.c lua.h auxlib.h lualib.h
+lua.o: lua.c lua.h auxlib.h lualib.h lualoc.h
 luamem.o: luamem.c luamem.h lua.h
 mathlib.o: mathlib.c lualib.h lua.h auxlib.h
 opcode.o: opcode.c luadebug.h lua.h luamem.h opcode.h types.h tree.h \
- func.h hash.h inout.h table.h fallback.h auxlib.h lex.h zio.h
+ func.h hash.h inout.h table.h fallback.h auxlib.h lex.h zio.h lualoc.h
 parser.o: parser.c luadebug.h lua.h luamem.h lex.h zio.h opcode.h \
  types.h tree.h func.h hash.h inout.h table.h
 strlib.o: strlib.c lua.h auxlib.h lualib.h

+ 3 - 2
opcode.c

@@ -3,13 +3,14 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_opcode="$Id: opcode.c,v 4.14 1997/06/23 18:27:53 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 4.15 1997/06/26 21:40:57 roberto Exp roberto $";
 
 #include <setjmp.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
+#include "lualoc.h"
 #include "luadebug.h"
 #include "luamem.h"
 #include "opcode.h"
@@ -1027,7 +1028,7 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal,
   if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER)
     result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1;
   else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING)
-    result = strcmp(svalue(l), svalue(r));
+    result = strcoll(svalue(l), svalue(r));
   else {
     call_binTM(op, "unexpected type at comparison");
     return;