Changeset 531

Show
Ignore:
Timestamp:
08/09/07 00:28:51 (1 year ago)
Author:
goodea
Message:

Resync to Lua 5.1.2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/lua51/Makefile.orig

    r269 r531  
    2121# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE ========= 
    2222 
    23 PLATS= aix ansi bsd generic linux macosx mingw posix solaris 
     23PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris 
    2424 
    2525LUA_A=  liblua.a 
     
    7878 
    7979none: 
    80         @echo "Please choose a platform: $(PLATS)" 
     80        @echo "Please choose a platform:" 
     81        @echo "   $(PLATS)" 
    8182 
    8283aix: 
     
    8889bsd: 
    8990        $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E" 
     91 
     92freebsd: 
     93        $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline" 
    9094 
    9195generic: 
     
    104108        "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ 
    105109        "MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe 
     110        $(MAKE) "LUAC_T=luac.exe" luac.exe 
    106111 
    107112posix: 
  • trunk/lib/lua51/README.txt

    r269 r531  
    1 This is based on Lua 5.1.1
     1This is based on Lua 5.1.2
    22 
    33Please see the copyright notice in lua.h. 
  • trunk/lib/lua51/lbaselib.c

    r269 r531  
    11/* 
    2 ** $Id: lbaselib.c,v 1.191 2006/06/02 15:34:00 roberto Exp $ 
     2** $Id: lbaselib.c,v 1.191a 2006/06/02 15:34:00 roberto Exp $ 
    33** Basic library 
    44** See Copyright Notice in lua.h 
     
    115115 
    116116 
    117 static void getfunc (lua_State *L) { 
     117static void getfunc (lua_State *L, int opt) { 
    118118  if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); 
    119119  else { 
    120120    lua_Debug ar; 
    121     int level = luaL_optint(L, 1, 1); 
     121    int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); 
    122122    luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); 
    123123    if (lua_getstack(L, level, &ar) == 0) 
     
    132132 
    133133static int luaB_getfenv (lua_State *L) { 
    134   getfunc(L); 
     134  getfunc(L, 1); 
    135135  if (lua_iscfunction(L, -1))  /* is a C function? */ 
    136136    lua_pushvalue(L, LUA_GLOBALSINDEX);  /* return the thread's global env. */ 
     
    143143static int luaB_setfenv (lua_State *L) { 
    144144  luaL_checktype(L, 2, LUA_TTABLE); 
    145   getfunc(L); 
     145  getfunc(L, 0); 
    146146  lua_pushvalue(L, 2); 
    147147  if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { 
  • trunk/lib/lua51/lcode.c

    r270 r531  
    11/* 
    2 ** $Id: lcode.c,v 2.25 2006/03/21 19:28:49 roberto Exp $ 
     2** $Id: lcode.c,v 2.25a 2006/03/21 19:28:49 roberto Exp $ 
    33** Code generator for Lua 
    44** See Copyright Notice in lua.h 
     
    3636  Instruction *previous; 
    3737  if (fs->pc > fs->lasttarget) {  /* no jumps to current position? */ 
    38     if (fs->pc == 0)  /* function start? */ 
    39       return;  /* positions are already clean */ 
    40     if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) { 
    41       int pfrom = GETARG_A(*previous); 
    42       int pto = GETARG_B(*previous); 
    43       if (pfrom <= from && from <= pto+1) {  /* can connect both? */ 
    44         if (from+n-1 > pto) 
    45           SETARG_B(*previous, from+n-1); 
    46         return; 
     38    if (fs->pc == 0) {  /* function start? */ 
     39      if (from >= fs->nactvar) 
     40        return;  /* positions are already clean */ 
     41    } 
     42    else { 
     43      previous = &fs->f->code[fs->pc-1]; 
     44      if (GET_OPCODE(*previous) == OP_LOADNIL) { 
     45        int pfrom = GETARG_A(*previous); 
     46        int pto = GETARG_B(*previous); 
     47        if (pfrom <= from && from <= pto+1) {  /* can connect both? */ 
     48          if (from+n-1 > pto) 
     49            SETARG_B(*previous, from+n-1); 
     50          return; 
     51        } 
    4752      } 
    4853    } 
     
    658663    return; 
    659664  else { 
     665    int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; 
    660666    int o1 = luaK_exp2RK(fs, e1); 
    661     int o2 = (op != OP_UNM && op != OP_LEN) ? luaK_exp2RK(fs, e2) : 0; 
    662     freeexp(fs, e2); 
    663     freeexp(fs, e1); 
     667    if (o1 > o2) { 
     668      freeexp(fs, e1); 
     669      freeexp(fs, e2); 
     670    } 
     671    else { 
     672      freeexp(fs, e2); 
     673      freeexp(fs, e1); 
     674    } 
    664675    e1->u.s.info = luaK_codeABC(fs, op, 0, o1, o2); 
    665676    e1->k = VRELOCABLE; 
     
    719730      break; 
    720731    } 
     732    case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV: 
     733    case OPR_MOD: case OPR_POW: { 
     734      if (!isnumeral(v)) luaK_exp2RK(fs, v); 
     735      break; 
     736    } 
    721737    default: { 
    722       if (!isnumeral(v)) luaK_exp2RK(fs, v); 
     738      luaK_exp2RK(fs, v); 
    723739      break; 
    724740    } 
  • trunk/lib/lua51/ldebug.c

    r269 r531  
    11/* 
    2 ** $Id: ldebug.c,v 2.29 2005/12/22 16:19:56 roberto Exp $ 
     2** $Id: ldebug.c,v 2.29a 2005/12/22 16:19:56 roberto Exp $ 
    33** Debug Interface 
    44** See Copyright Notice in lua.h 
     
    433433      } 
    434434      case OP_CLOSURE: { 
    435         int nup
     435        int nup, j
    436436        check(b < pt->sizep); 
    437437        nup = pt->p[b]->nups; 
    438438        check(pc + nup < pt->sizecode); 
    439         for (; nup>0; nup--) { 
    440           OpCode op1 = GET_OPCODE(pt->code[pc+nup]); 
     439        for (j = 1; j <= nup; j++) { 
     440          OpCode op1 = GET_OPCODE(pt->code[pc + j]); 
    441441          check(op1 == OP_GETUPVAL || op1 == OP_MOVE); 
    442442        } 
     443        if (reg != NO_REG)  /* tracing? */ 
     444          pc += nup;  /* do not 'execute' these pseudo-instructions */ 
    443445        break; 
    444446      } 
  • trunk/lib/lua51/lfunc.c

    r269 r531  
    11/* 
    2 ** $Id: lfunc.c,v 2.12 2005/12/22 16:19:56 roberto Exp $ 
     2** $Id: lfunc.c,v 2.12a 2005/12/22 16:19:56 roberto Exp $ 
    33** Auxiliary functions to manipulate prototypes and closures 
    44** See Copyright Notice in lua.h 
     
    5656  UpVal *p; 
    5757  UpVal *uv; 
    58   while ((p = ngcotouv(*pp)) != NULL && p->v >= level) { 
     58  while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) { 
    5959    lua_assert(p->v != &p->u.value); 
    6060    if (p->v == level) {  /* found a corresponding upvalue? */ 
     
    9797  UpVal *uv; 
    9898  global_State *g = G(L); 
    99   while ((uv = ngcotouv(L->openupval)) != NULL && uv->v >= level) { 
     99  while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) { 
    100100    GCObject *o = obj2gco(uv); 
    101101    lua_assert(!isblack(o) && uv->v != &uv->u.value); 
  • trunk/lib/lua51/linit.c

    r270 r531  
    2222  {LUA_OSLIBNAME, luaopen_os}, 
    2323  {LUA_STRLIBNAME, luaopen_string}, 
    24 #if !defined LUA_NUMBER_INTEGRAL 
    2524  {LUA_MATHLIBNAME, luaopen_math}, 
    26 #endif 
    2725  {LUA_DBLIBNAME, luaopen_debug}, 
    2826  {NULL, NULL} 
  • trunk/lib/lua51/lmathlib.c

    r270 r531  
    253253  lua_pushnumber(L, PI); 
    254254  lua_setfield(L, -2, "pi"); 
    255 #if !defined LUA_NUMBER_INTEGRAL 
    256255  lua_pushnumber(L, HUGE_VAL); 
    257256  lua_setfield(L, -2, "huge"); 
    258 #endif 
    259257#if defined(LUA_COMPAT_MOD) 
    260258  lua_getfield(L, -1, "fmod"); 
  • trunk/lib/lua51/loadlib.c

    r270 r531  
    11/* 
    2 ** $Id: loadlib.c,v 1.52 2006/04/10 18:27:23 roberto Exp $ 
     2** $Id: loadlib.c,v 1.54a 2006/07/03 20:16:49 roberto Exp $ 
    33** Dynamic library loader for Lua 
    44** See Copyright Notice in lua.h 
     
    1717#define LUA_LIB 
    1818 
     19#include "lua.h" 
     20 
    1921#include "lauxlib.h" 
    20 #include "lobject.h" 
    21 #include "lua.h" 
    2222#include "lualib.h" 
    2323 
     
    9999  char *lb; 
    100100  DWORD nsize = sizeof(buff)/sizeof(char); 
    101   DWORD n = GetModuleFileName(NULL, buff, nsize); 
     101  DWORD n = GetModuleFileNameA(NULL, buff, nsize); 
    102102  if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) 
    103103    luaL_error(L, "unable to get ModuleFileName"); 
     
    113113  int error = GetLastError(); 
    114114  char buffer[128]; 
    115   if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, 
     115  if (FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, 
    116116      NULL, error, 0, buffer, sizeof(buffer), NULL)) 
    117117    lua_pushstring(L, buffer); 
     
    126126 
    127127static void *ll_load (lua_State *L, const char *path) { 
    128   HINSTANCE lib = LoadLibrary(path); 
     128  HINSTANCE lib = LoadLibraryA(path); 
    129129  if (lib == NULL) pusherror(L); 
    130130  return lib; 
     
    357357  if (path == NULL) 
    358358    luaL_error(L, LUA_QL("package.%s") " must be a string", pname); 
    359   lua_pushstring(L, "");  /* error accumulator */ 
     359  lua_pushliteral(L, "");  /* error accumulator */ 
    360360  while ((path = pushnexttemplate(L, path)) != NULL) { 
    361361    const char *filename; 
    362362    filename = luaL_gsub(L, lua_tostring(L, -1), LUA_PATH_MARK, name); 
     363    lua_remove(L, -2);  /* remove path template */ 
    363364    if (readable(filename))  /* does file exist and is readable? */ 
    364365      return filename;  /* return that file name */ 
    365     lua_pop(L, 2);  /* remove path template and file name */  
    366     luaO_pushfstring(L, "\n\tno file " LUA_QS, filename); 
    367     lua_concat(L, 2); 
     366    lua_pushfstring(L, "\n\tno file " LUA_QS, filename); 
     367    lua_remove(L, -2);  /* remove file name */ 
     368    lua_concat(L, 2);  /* add entry to possible error message */ 
    368369  } 
    369370  return NULL;  /* not found */ 
     
    424425  if ((stat = ll_loadfunc(L, filename, funcname)) != 0) { 
    425426    if (stat != ERRFUNC) loaderror(L, filename);  /* real error */ 
    426     luaO_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, 
    427                         name, filename); 
     427    lua_pushfstring(L, "\n\tno module " LUA_QS " in file " LUA_QS, 
     428                       name, filename); 
    428429    return 1;  /* function not found */ 
    429430  } 
     
    439440  lua_getfield(L, -1, name); 
    440441  if (lua_isnil(L, -1))  /* not found? */ 
    441     luaO_pushfstring(L, "\n\tno field package.preload['%s']", name); 
     442    lua_pushfstring(L, "\n\tno field package.preload['%s']", name); 
    442443  return 1; 
    443444} 
     
    463464  if (!lua_istable(L, -1)) 
    464465    luaL_error(L, LUA_QL("package.loaders") " must be a table"); 
    465   lua_pushstring(L, "");  /* error message accumulator */ 
     466  lua_pushliteral(L, "");  /* error message accumulator */ 
    466467  for (i=1; ; i++) { 
    467468    lua_rawgeti(L, -2, i);  /* get a loader */ 
     
    647648  setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); /* set field `cpath' */ 
    648649  /* store config information */ 
    649   lua_pushstring(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" 
    650                     LUA_EXECDIR "\n" LUA_IGMARK); 
     650  lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" 
     651                    LUA_EXECDIR "\n" LUA_IGMARK); 
    651652  lua_setfield(L, -2, "config"); 
    652653  /* set field `loaded' */ 
  • trunk/lib/lua51/loslib.c

    r270 r531  
    11/* 
    2 ** $Id: loslib.c,v 1.19 2006/04/26 18:19:49 roberto Exp $ 
     2** $Id: loslib.c,v 1.20 2006/09/19 13:57:08 roberto Exp $ 
    33** Standard Operating System library 
    44** See Copyright Notice in lua.h 
     
    147147  } 
    148148  else { 
    149     char b[256]; 
    150     if (strftime(b, sizeof(b), s, stm)) 
    151       lua_pushstring(L, b); 
    152     else 
    153       return luaL_error(L, LUA_QL("date") " format too long"); 
     149    char cc[3]; 
     150    luaL_Buffer b; 
     151    cc[0] = '%'; cc[2] = '\0'; 
     152    luaL_buffinit(L, &b); 
     153    for (; *s; s++) { 
     154      if (*s != '%' || *(s + 1) == '\0')  /* no conversion specifier? */ 
     155        luaL_addchar(&b, *s); 
     156      else { 
     157        size_t reslen; 
     158        char buff[200];  /* should be big enough for any conversion result */ 
     159        cc[1] = *(++s); 
     160        reslen = strftime(buff, sizeof(buff), cc, stm); 
     161        luaL_addlstring(&b, buff, reslen); 
     162      } 
     163    } 
     164    luaL_pushresult(&b); 
    154165  } 
    155166  return 1; 
     
    182193 
    183194 
    184 #if !defined LUA_NUMBER_INTEGRAL 
    185195static int os_difftime (lua_State *L) { 
    186196  lua_pushnumber(L, difftime((time_t)(luaL_checknumber(L, 1)), 
     
    188198  return 1; 
    189199} 
    190 #endif 
    191200 
    192201/* }====================================================== */ 
     
    213222  {"clock",     os_clock}, 
    214223  {"date",      os_date}, 
    215 #if !defined LUA_NUMBER_INTEGRAL 
    216224  {"difftime",  os_difftime}, 
    217 #endif 
    218225  {"execute",   os_execute}, 
    219226  {"exit",      os_exit}, 
  • trunk/lib/lua51/lparser.c

    r270 r531  
    11/* 
    2 ** $Id: lparser.c,v 2.42 2006/06/05 15:57:59 roberto Exp $ 
     2** $Id: lparser.c,v 2.42a 2006/06/05 15:57:59 roberto Exp $ 
    33** Lua Parser 
    44** See Copyright Notice in lua.h 
     
    490490static void listfield (LexState *ls, struct ConsControl *cc) { 
    491491  expr(ls, &cc->v); 
    492   luaY_checklimit(ls->fs, cc->na, MAXARG_Bx, "items in a constructor"); 
     492  luaY_checklimit(ls->fs, cc->na, MAX_INT, "items in a constructor"); 
    493493  cc->na++; 
    494494  cc->tostore++; 
  • trunk/lib/lua51/lstrlib.c

    r270 r531  
    11/* 
    2 ** $Id: lstrlib.c,v 1.132 2006/04/26 20:41:19 roberto Exp $ 
     2** $Id: lstrlib.c,v 1.132a 2006/04/26 20:41:19 roberto Exp $ 
    33** Standard library for string operations and pattern-matching 
    44** See Copyright Notice in lua.h 
     
    724724static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { 
    725725  const char *p = strfrmt; 
    726   while (strchr(FLAGS, *p)) p++;  /* skip flags */ 
     726  while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++;  /* skip flags */ 
    727727  if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) 
    728728    luaL_error(L, "invalid format (repeated flags)"); 
     
    785785          break; 
    786786        } 
    787 #if !defined LUA_NUMBER_INTEGRAL 
    788787        case 'e':  case 'E': case 'f': 
    789788        case 'g': case 'G': { 
     
    791790          break; 
    792791        } 
    793 #endif 
    794792        case 'q': { 
    795793          addquoted(L, &b, arg); 
  • trunk/lib/lua51/lua.h

    r270 r531  
    11/* 
    2 ** $Id: lua.h,v 1.218 2006/06/02 15:34:00 roberto Exp $ 
     2** $Id: lua.h,v 1.218a 2006/06/02 15:34:00 roberto Exp $ 
    33** Lua - An Extensible Extension Language 
    44** Lua.org, PUC-Rio, Brazil (http://www.lua.org) 
     
    1818 
    1919#define LUA_VERSION     "Lua 5.1" 
    20 #define LUA_RELEASE     "Lua 5.1.1
     20#define LUA_RELEASE     "Lua 5.1.2
    2121#define LUA_VERSION_NUM 501 
    22 #define LUA_COPYRIGHT   "Copyright (C) 1994-2006 Lua.org, PUC-Rio" 
     22#define LUA_COPYRIGHT   "Copyright (C) 1994-2007 Lua.org, PUC-Rio" 
    2323#define LUA_AUTHORS     "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" 
    2424 
     
    360360 
    361361/****************************************************************************** 
    362 * Copyright (C) 1994-2006 Lua.org, PUC-Rio.  All rights reserved. 
     362* Copyright (C) 1994-2007 Lua.org, PUC-Rio.  All rights reserved. 
    363363* 
    364364* Permission is hereby granted, free of charge, to any person obtaining 
  • trunk/lib/lua51/luaconf.h

    r327 r531  
    11/* 
    2 ** $Id: luaconf.h,v 1.82 2006/04/10 18:27:23 roberto Exp $ 
     2** $Id: luaconf.h,v 1.82a 2006/04/10 18:27:23 roberto Exp $ 
    33** Configuration file for Lua 
    44** See Copyright Notice in lua.h 
     
    141141** machines, ptrdiff_t gives a good choice between int or long.) 
    142142*/ 
    143  
    144 /* Changed to long for use with integral Lua numbers. */ 
    145 #define LUA_INTEGER     long 
     143#define LUA_INTEGER     ptrdiff_t 
     144 
    146145 
    147146/* 
     
    362361@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib' 
    363362@* behavior. 
    364 ** CHANGE it to undefined as soon as you replace to 'luaL_registry
     363** CHANGE it to undefined as soon as you replace to 'luaL_register
    365364** your uses of 'luaL_openlib' 
    366365*/ 
     
    502501*/ 
    503502 
    504 /* Define LUA_NUMBER_INTEGRAL to produce a system that uses no 
    505    floating point operations by changing the type of Lua numbers from 
    506    double to long.  It implements division and modulus so that  
    507  
    508    x == (x / y) * y + x % y.   
    509     
    510    The exponentiation function returns zero for negative exponents. 
    511    Defining LUA_NUMBER_INTEGRAL also removes the difftime function, 
    512    and the math module should not be used.  The string.format function 
    513    no longer handles the floating point directives %e, %E, %f, %g, and 
    514    %G. */ 
    515  
    516 #define LUA_NUMBER_INTEGRAL 
    517 #if defined LUA_NUMBER_INTEGRAL 
    518 #define LUA_NUMBER      long 
    519 #else 
    520503#define LUA_NUMBER_DOUBLE 
    521504#define LUA_NUMBER      double 
    522 #endif 
    523505 
    524506/* 
     
    526508@* over a number. 
    527509*/ 
    528 #define LUAI_UACNUMBER  LUA_NUMBER 
     510#define LUAI_UACNUMBER  double 
    529511 
    530512 
     
    536518@@ lua_str2number converts a string to a number. 
    537519*/ 
    538 #if defined LUA_NUMBER_INTEGRAL 
    539 #define LUA_NUMBER_SCAN         "%ld" 
    540 #define LUA_NUMBER_FMT          "%ld" 
    541 #else 
    542520#define LUA_NUMBER_SCAN         "%lf" 
    543521#define LUA_NUMBER_FMT          "%.14g" 
    544 #endif 
    545522#define lua_number2str(s,n)     sprintf((s), LUA_NUMBER_FMT, (n)) 
    546523#define LUAI_MAXNUMBER2STR      32 /* 16 digits, sign, point, and \0 */ 
    547 #if defined LUA_NUMBER_INTEGRAL 
    548 #define lua_str2number(s,p)     strtol((s), (p), 10) 
    549 #else 
    550524#define lua_str2number(s,p)     strtod((s), (p)) 
    551 #endif 
    552525 
    553526 
     
    560533#define luai_numsub(a,b)        ((a)-(b)) 
    561534#define luai_nummul(a,b)        ((a)*(b)) 
    562 #if defined LUA_NUMBER_INTEGRAL 
    563 #define luai_numdiv(a,b)        \ 
    564   (-1/2?                        \ 
    565    (a)/(b):                     \ 
    566    ((a)<0==(b)<0||(a)%(b)==0?   \ 
    567     (a)/(b):                    \ 
    568     (a)/(b)-1)) 
    569 #define luai_nummod(a,b)        \ 
    570   (-1/2?                        \ 
    571    (a)%(b):                     \ 
    572    ((a)<0==(b)<0||(a)%(b)==0?   \ 
    573     (a)%(b):                    \ 
    574     (a)%(b)+(b))) 
    575 #define luai_lnumdiv(a,b)       \ 
    576   ((b)==0?                      \ 
    577    (luaG_runerror(L,"divide by zero"),0): \ 
    578    luai_numdiv(a,b)) 
    579 #define luai_lnummod(a,b)       \ 
    580   ((b)==0?                      \ 
    581    (luaG_runerror(L,"modulo by zero"),0): \ 
    582    luai_nummod(a,b)) 
    583 LUA_NUMBER luai_ipow(LUA_NUMBER, LUA_NUMBER); 
    584 #define luai_numpow(a,b)        (luai_ipow(a,b)) 
    585 #else 
    586535#define luai_numdiv(a,b)        ((a)/(b)) 
    587536#define luai_nummod(a,b)        ((a) - floor((a)/(b))*(b)) 
    588 #define luai_lnumdiv(a,b)       (luai_numdiv(a,b)) 
    589 #define luai_lnummod(a,b)       (luai_nummod(a,b)) 
    590537#define luai_numpow(a,b)        (pow(a,b)) 
    591 #endif 
    592538#define luai_numunm(a)          (-(a)) 
    593539#define luai_numeq(a,b)         ((a)==(b)) 
  • trunk/lib/lua51/lvm.c

    r270 r531  
    11/* 
    2 ** $Id: lvm.c,v 2.63 2006/06/05 15:58:59 roberto Exp $ 
     2** $Id: lvm.c,v 2.63a 2006/06/05 15:58:59 roberto Exp $ 
    33** Lua virtual machine 
    44** See Copyright Notice in lua.h 
     
    2828 
    2929 
    30 #if defined LUA_NUMBER_INTEGRAL 
    31 LUA_NUMBER luai_ipow(LUA_NUMBER a, LUA_NUMBER b) { 
    32   if (b < 0) 
    33     return 0; 
    34   else if (b == 0) 
    35     return 1; 
    36   else { 
    37     LUA_NUMBER c = 1; 
    38     for (;;) { 
    39       if (b & 1) 
    40         c *= a; 
    41       b = b >> 1; 
    42       if (b == 0) 
    43         return c; 
    44       a *= a; 
    45     } 
    46   } 
    47 } 
    48 #endif 
    4930 
    5031/* limit for table tag-method chains (to avoid loops) */ 
     
    185166  if (ttisnil(tm)) 
    186167    tm = luaT_gettmbyobj(L, p2, event);  /* try second operand */ 
    187   if (!ttisfunction(tm)) return 0; 
     168  if (ttisnil(tm)) return 0; 
    188169  callTMres(L, res, tm, p1, p2); 
    189170  return 1; 
     
    301282    StkId top = L->base + last + 1; 
    302283    int n = 2;  /* number of elements handled in this pass (at least 2) */ 
    303     if (!tostring(L, top-2) || !tostring(L, top-1)) { 
     284    if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { 
    304285      if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) 
    305286        luaG_concaterror(L, top-2, top-1); 
    306     } else if (tsvalue(top-1)->len > 0) {  /* if len=0, do nothing */ 
     287    } else if (tsvalue(top-1)->len == 0)  /* second op is empty? */ 
     288      (void)tostring(L, top - 2);  /* result is first op (as string) */ 
     289    else { 
    307290      /* at least two string values; get as many as possible */ 
    308291      size_t tl = tsvalue(top-1)->len; 
     
    341324      case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break; 
    342325      case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break; 
    343       case TM_DIV: setnvalue(ra, luai_lnumdiv(nb, nc)); break; 
    344       case TM_MOD: setnvalue(ra, luai_lnummod(nb, nc)); break; 
     326      case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break; 
     327      case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break; 
    345328      case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break; 
    346329      case TM_UNM: setnvalue(ra, luai_numunm(nb)); break; 
     
    500483      } 
    501484      case OP_DIV: { 
    502         arith_op(luai_lnumdiv, TM_DIV); 
     485        arith_op(luai_numdiv, TM_DIV); 
    503486        continue; 
    504487      } 
    505488      case OP_MOD: { 
    506         arith_op(luai_lnummod, TM_MOD); 
     489        arith_op(luai_nummod, TM_MOD); 
    507490        continue; 
    508491      } 
  • trunk/lib/lua51/print.c

    r270 r531  
    11/* 
    2 ** $Id: print.c,v 1.55 2006/05/31 13:30:05 lhf Exp $ 
     2** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $ 
    33** print bytecodes 
    44** See Copyright Notice in lua.h 
     
    2424{ 
    2525 const char* s=getstr(ts); 
    26  int n=ts->tsv.len; 
    27  int i; 
     26 size_t i,n=ts->tsv.len; 
    2827 putchar('"'); 
    2928 for (i=0; i<n; i++) 
     
    3332  { 
    3433   case '"': printf("\\\""); break; 
     34   case '\\': printf("\\\\"); break; 
    3535   case '\a': printf("\\a"); break; 
    3636   case '\b': printf("\\b"); break;