diff options
| -rw-r--r-- | iolib.c | 14 | ||||
| -rw-r--r-- | lex.c | 54 | ||||
| -rw-r--r-- | lua.c | 4 | ||||
| -rw-r--r-- | makefile | 21 | ||||
| -rw-r--r-- | opcode.c | 5 |
5 files changed, 53 insertions, 45 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}, |
| @@ -1,4 +1,4 @@ | |||
| 1 | char *rcs_lex = "$Id: lex.c,v 3.4 1997/06/11 18:56:02 roberto Exp roberto $"; | 1 | char *rcs_lex = "$Id: lex.c,v 3.5 1997/06/16 16:50:22 roberto Exp roberto $"; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | #include <ctype.h> | 4 | #include <ctype.h> |
| @@ -278,11 +278,9 @@ int luaY_lex (void) | |||
| 278 | if (lua_debug) | 278 | if (lua_debug) |
| 279 | luaI_codedebugline(linelasttoken); | 279 | luaI_codedebugline(linelasttoken); |
| 280 | linelasttoken = lua_linenumber; | 280 | linelasttoken = lua_linenumber; |
| 281 | while (1) | 281 | while (1) { |
| 282 | { | ||
| 283 | int tokensize = 0; | 282 | int tokensize = 0; |
| 284 | switch (current) | 283 | switch (current) { |
| 285 | { | ||
| 286 | case '\n': | 284 | case '\n': |
| 287 | inclinenumber(); | 285 | inclinenumber(); |
| 288 | linelasttoken = lua_linenumber; | 286 | linelasttoken = lua_linenumber; |
| @@ -365,33 +363,6 @@ int luaY_lex (void) | |||
| 365 | return STRING; | 363 | return STRING; |
| 366 | } | 364 | } |
| 367 | 365 | ||
| 368 | case 'a': case 'b': case 'c': case 'd': case 'e': | ||
| 369 | case 'f': case 'g': case 'h': case 'i': case 'j': | ||
| 370 | case 'k': case 'l': case 'm': case 'n': case 'o': | ||
| 371 | case 'p': case 'q': case 'r': case 's': case 't': | ||
| 372 | case 'u': case 'v': case 'w': case 'x': case 'y': | ||
| 373 | case 'z': | ||
| 374 | case 'A': case 'B': case 'C': case 'D': case 'E': | ||
| 375 | case 'F': case 'G': case 'H': case 'I': case 'J': | ||
| 376 | case 'K': case 'L': case 'M': case 'N': case 'O': | ||
| 377 | case 'P': case 'Q': case 'R': case 'S': case 'T': | ||
| 378 | case 'U': case 'V': case 'W': case 'X': case 'Y': | ||
| 379 | case 'Z': | ||
| 380 | case '_': | ||
| 381 | { | ||
| 382 | TaggedString *ts; | ||
| 383 | do { | ||
| 384 | save_and_next(); | ||
| 385 | } while (isalnum((unsigned char)current) || current == '_'); | ||
| 386 | save(0); | ||
| 387 | ts = lua_createstring(yytext); | ||
| 388 | if (ts->marked > 2) | ||
| 389 | return ts->marked; /* reserved word */ | ||
| 390 | luaY_lval.pTStr = ts; | ||
| 391 | ts->marked = 2; /* avoid GC */ | ||
| 392 | return NAME; | ||
| 393 | } | ||
| 394 | |||
| 395 | case '.': | 366 | case '.': |
| 396 | save_and_next(); | 367 | save_and_next(); |
| 397 | if (current == '.') | 368 | if (current == '.') |
| @@ -462,8 +433,23 @@ int luaY_lex (void) | |||
| 462 | return 0; | 433 | return 0; |
| 463 | 434 | ||
| 464 | default: | 435 | default: |
| 465 | save_and_next(); | 436 | if (current != '_' && !isalpha((unsigned char)current)) { |
| 466 | return yytext[0]; | 437 | save_and_next(); |
| 438 | return yytext[0]; | ||
| 439 | } | ||
| 440 | else { /* identifier or reserved word */ | ||
| 441 | TaggedString *ts; | ||
| 442 | do { | ||
| 443 | save_and_next(); | ||
| 444 | } while (isalnum((unsigned char)current) || current == '_'); | ||
| 445 | save(0); | ||
| 446 | ts = lua_createstring(yytext); | ||
| 447 | if (ts->marked > 2) | ||
| 448 | return ts->marked; /* reserved word */ | ||
| 449 | luaY_lval.pTStr = ts; | ||
| 450 | ts->marked = 2; /* avoid GC */ | ||
| 451 | return NAME; | ||
| 452 | } | ||
| 467 | } | 453 | } |
| 468 | } | 454 | } |
| 469 | } | 455 | } |
| @@ -3,11 +3,12 @@ | |||
| 3 | ** Linguagem para Usuarios de Aplicacao | 3 | ** Linguagem para Usuarios de Aplicacao |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_lua="$Id: lua.c,v 1.17 1997/06/18 21:20:45 roberto Exp roberto $"; | 6 | char *rcs_lua="$Id: lua.c,v 1.18 1997/06/19 18:55:40 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| 10 | 10 | ||
| 11 | #include "lualoc.h" | ||
| 11 | #include "lua.h" | 12 | #include "lua.h" |
| 12 | #include "auxlib.h" | 13 | #include "auxlib.h" |
| 13 | #include "lualib.h" | 14 | #include "lualib.h" |
| @@ -107,6 +108,7 @@ int main (int argc, char *argv[]) | |||
| 107 | { | 108 | { |
| 108 | int i; | 109 | int i; |
| 109 | int result = 0; | 110 | int result = 0; |
| 111 | setlocale(LC_ALL, ""); | ||
| 110 | iolib_open (); | 112 | iolib_open (); |
| 111 | strlib_open (); | 113 | strlib_open (); |
| 112 | mathlib_open (); | 114 | mathlib_open (); |
| @@ -1,18 +1,25 @@ | |||
| 1 | # $Id: makefile,v 1.35 1997/06/16 16:50:22 roberto Exp roberto $ | 1 | # $Id: makefile,v 1.36 1997/06/23 18:27:53 roberto Exp roberto $ |
| 2 | 2 | ||
| 3 | #configuration | 3 | #configuration |
| 4 | 4 | ||
| 5 | # define (undefine) POPEN if your system (does not) support piped I/O | 5 | # define (undefine) POPEN if your system (does not) support piped I/O |
| 6 | # | ||
| 6 | # define (undefine) _POSIX_SOURCE if your system is (not) POSIX compliant | 7 | # define (undefine) _POSIX_SOURCE if your system is (not) POSIX compliant |
| 7 | #define (undefine) NOSTRERROR if your system does NOT have function "strerror" | 8 | # |
| 8 | # (although this is ANSI, SunOS does not comply; so, add "-DNOSTRERROR" on SunOS) | 9 | # define (undefine) OLD_ANSI if your system does NOT have some new ANSI |
| 10 | # facilities ("strerror" and "locale.h"). Although they are ANSI, | ||
| 11 | # SunOS does not comply; so, add "-DOLD_ANSI" on SunOS | ||
| 12 | # | ||
| 9 | # define LUA_COMPAT2_5=0 if yous system does not need to be compatible with | 13 | # define LUA_COMPAT2_5=0 if yous system does not need to be compatible with |
| 10 | # version 2.5 (or older) | 14 | # version 2.5 (or older) |
| 15 | |||
| 11 | CONFIG = -DPOPEN -D_POSIX_SOURCE | 16 | CONFIG = -DPOPEN -D_POSIX_SOURCE |
| 17 | |||
| 18 | |||
| 12 | # Compilation parameters | 19 | # Compilation parameters |
| 13 | CC = gcc | 20 | CC = gcc |
| 14 | CWARNS = -Wall -Wmissing-prototypes -Wshadow -pedantic -Wpointer-arith -Wcast-align -Waggregate-return | 21 | CWARNS = -Wall -Wmissing-prototypes -Wshadow -pedantic -Wpointer-arith -Wcast-align -Waggregate-return |
| 15 | CFLAGS = $(CONFIG) $(CWARNS) -ansi -O2 -fomit-frame-pointer | 22 | CFLAGS = $(CONFIG) $(CWARNS) -ansi -O2 |
| 16 | 23 | ||
| 17 | #CC = acc | 24 | #CC = acc |
| 18 | #CFLAGS = -fast -I/usr/5include | 25 | #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 \ | |||
| 89 | table.h auxlib.h | 96 | table.h auxlib.h |
| 90 | inout.o: inout.c auxlib.h lua.h fallback.h opcode.h types.h tree.h \ | 97 | inout.o: inout.c auxlib.h lua.h fallback.h opcode.h types.h tree.h \ |
| 91 | func.h hash.h inout.h lex.h zio.h luamem.h table.h undump.h | 98 | func.h hash.h inout.h lex.h zio.h luamem.h table.h undump.h |
| 92 | iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.h | 99 | iolib.o: iolib.c lua.h auxlib.h luadebug.h lualib.h lualoc.h |
| 93 | lex.o: lex.c auxlib.h lua.h luamem.h tree.h types.h table.h opcode.h \ | 100 | lex.o: lex.c auxlib.h lua.h luamem.h tree.h types.h table.h opcode.h \ |
| 94 | func.h lex.h zio.h inout.h luadebug.h parser.h | 101 | func.h lex.h zio.h inout.h luadebug.h parser.h |
| 95 | lua.o: lua.c lua.h auxlib.h lualib.h | 102 | lua.o: lua.c lua.h auxlib.h lualib.h lualoc.h |
| 96 | luamem.o: luamem.c luamem.h lua.h | 103 | luamem.o: luamem.c luamem.h lua.h |
| 97 | mathlib.o: mathlib.c lualib.h lua.h auxlib.h | 104 | mathlib.o: mathlib.c lualib.h lua.h auxlib.h |
| 98 | opcode.o: opcode.c luadebug.h lua.h luamem.h opcode.h types.h tree.h \ | 105 | opcode.o: opcode.c luadebug.h lua.h luamem.h opcode.h types.h tree.h \ |
| 99 | func.h hash.h inout.h table.h fallback.h auxlib.h lex.h zio.h | 106 | func.h hash.h inout.h table.h fallback.h auxlib.h lex.h zio.h lualoc.h |
| 100 | parser.o: parser.c luadebug.h lua.h luamem.h lex.h zio.h opcode.h \ | 107 | parser.o: parser.c luadebug.h lua.h luamem.h lex.h zio.h opcode.h \ |
| 101 | types.h tree.h func.h hash.h inout.h table.h | 108 | types.h tree.h func.h hash.h inout.h table.h |
| 102 | strlib.o: strlib.c lua.h auxlib.h lualib.h | 109 | strlib.o: strlib.c lua.h auxlib.h lualib.h |
| @@ -3,13 +3,14 @@ | |||
| 3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_opcode="$Id: opcode.c,v 4.14 1997/06/23 18:27:53 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 4.15 1997/06/26 21:40:57 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| 10 | #include <string.h> | 10 | #include <string.h> |
| 11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| 12 | 12 | ||
| 13 | #include "lualoc.h" | ||
| 13 | #include "luadebug.h" | 14 | #include "luadebug.h" |
| 14 | #include "luamem.h" | 15 | #include "luamem.h" |
| 15 | #include "opcode.h" | 16 | #include "opcode.h" |
| @@ -1027,7 +1028,7 @@ static void comparison (lua_Type ttype_less, lua_Type ttype_equal, | |||
| 1027 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) | 1028 | if (ttype(l) == LUA_T_NUMBER && ttype(r) == LUA_T_NUMBER) |
| 1028 | result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; | 1029 | result = (nvalue(l) < nvalue(r)) ? -1 : (nvalue(l) == nvalue(r)) ? 0 : 1; |
| 1029 | else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) | 1030 | else if (ttype(l) == LUA_T_STRING && ttype(r) == LUA_T_STRING) |
| 1030 | result = strcmp(svalue(l), svalue(r)); | 1031 | result = strcoll(svalue(l), svalue(r)); |
| 1031 | else { | 1032 | else { |
| 1032 | call_binTM(op, "unexpected type at comparison"); | 1033 | call_binTM(op, "unexpected type at comparison"); |
| 1033 | return; | 1034 | return; |
