Changeset 266

Show
Ignore:
Timestamp:
07/09/06 16:58:32 (2 years ago)
Author:
goodea
Message:

update to 5.1.1

Files:

Legend:

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

    r141 r266  
    8181 
    8282aix: 
    83         $(MAKE) all CC="xlc" CFLAGS="-O2" MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall" 
     83        $(MAKE) all CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall" 
    8484 
    8585ansi: 
     
    122122lbaselib.o: lbaselib.c lua.h luaconf.h lauxlib.h lualib.h 
    123123lcode.o: lcode.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ 
    124   lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ 
    125   ldo.h lgc.h 
     124  lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h lgc.h \ 
     125  ltable.h 
    126126ldblib.o: ldblib.c lua.h luaconf.h lauxlib.h lualib.h 
    127127ldebug.o: ldebug.c lua.h luaconf.h lapi.h lobject.h llimits.h lcode.h \ 
    128   llex.h lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h \ 
    129   ltm.h ldo.h lfunc.h lstring.h lgc.h lvm.h 
     128  llex.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ 
     129  lfunc.h lstring.h lgc.h ltable.h lvm.h 
    130130ldo.o: ldo.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h ltm.h \ 
    131   lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h ltable.h \ 
    132   lstring.h lundump.h lvm.h 
     131  lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lparser.h lstring.h \ 
     132  ltable.h lundump.h lvm.h 
    133133ldump.o: ldump.c lua.h luaconf.h lobject.h llimits.h lstate.h ltm.h \ 
    134134  lzio.h lmem.h lundump.h 
     
    140140liolib.o: liolib.c lua.h luaconf.h lauxlib.h lualib.h 
    141141llex.o: llex.c lua.h luaconf.h ldo.h lobject.h llimits.h lstate.h ltm.h \ 
    142   lzio.h lmem.h llex.h lparser.h ltable.h lstring.h lgc.h 
     142  lzio.h lmem.h llex.h lparser.h lstring.h lgc.h ltable.h 
    143143lmathlib.o: lmathlib.c lua.h luaconf.h lauxlib.h lualib.h 
    144144lmem.o: lmem.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ 
     
    151151loslib.o: loslib.c lua.h luaconf.h lauxlib.h lualib.h 
    152152lparser.o: lparser.c lua.h luaconf.h lcode.h llex.h lobject.h llimits.h \ 
    153   lzio.h lmem.h lopcodes.h lparser.h ltable.h ldebug.h lstate.h ltm.h \ 
    154   ldo.h lfunc.h lstring.h lgc.h 
     153  lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h ldo.h \ 
     154  lfunc.h lstring.h lgc.h ltable.h 
    155155lstate.o: lstate.c lua.h luaconf.h ldebug.h lstate.h lobject.h llimits.h \ 
    156156  ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h llex.h lstring.h ltable.h 
  • trunk/lib/lua51/lapi.c

    r198 r266  
    3333 
    3434const char lua_ident[] = 
    35   "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n" 
     35  "$Lua: " LUA_RELEASE " " LUA_COPYRIGHT " $\n" 
    3636  "$Authors: " LUA_AUTHORS " $\n" 
    3737  "$URL: www.lua.org $\n"; 
     
    200200  StkId o; 
    201201  lua_lock(L); 
     202  /* explicit test for incompatible code */ 
     203  if (idx == LUA_ENVIRONINDEX && L->ci == L->base_ci) 
     204    luaG_runerror(L, "no calling environment"); 
    202205  api_checknelems(L, 1); 
    203206  o = index2adr(L, idx); 
  • trunk/lib/lua51/lauxlib.c

    r198 r266  
    124124LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { 
    125125  void *p = lua_touserdata(L, ud); 
    126   lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */ 
    127   if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2)) 
    128     luaL_typerror(L, ud, tname); 
    129   lua_pop(L, 2);  /* remove both metatables */ 
    130   return p; 
     126  if (p != NULL) {  /* value is a userdata? */ 
     127    if (lua_getmetatable(L, ud)) {  /* does it have a metatable? */ 
     128      lua_getfield(L, LUA_REGISTRYINDEX, tname);  /* get correct metatable */ 
     129      if (lua_rawequal(L, -1, -2)) {  /* does it have the correct mt? */ 
     130        lua_pop(L, 2);  /* remove both metatables */ 
     131        return p; 
     132      } 
     133    } 
     134  } 
     135  luaL_typerror(L, ud, tname);  /* else error */ 
     136  return NULL;  /* to avoid warnings */ 
    131137} 
    132138 
  • trunk/lib/lua51/lauxlib.h

    r199 r266  
    109109#define luaL_typename(L,i)      lua_typename(L, lua_type(L,(i))) 
    110110 
    111 #define luaL_dofile(L, fn)      (luaL_loadfile(L, fn) || lua_pcall(L, 0, 0, 0)) 
     111#define luaL_dofile(L, fn) \ 
     112        (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 
    112113 
    113 #define luaL_dostring(L, s)     (luaL_loadstring(L, s) || lua_pcall(L, 0, 0, 0)) 
     114#define luaL_dostring(L, s) \ 
     115        (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 
    114116 
    115117#define luaL_getmetatable(L,n)  (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 
  • trunk/lib/lua51/lcode.c

    r198 r266  
    732732      lua_assert(e1->t == NO_JUMP);  /* list must be closed */ 
    733733      luaK_dischargevars(fs, e2); 
    734       luaK_concat(fs, &e1->f, e2->f); 
    735       e1->k = e2->k; e1->u.s.info = e2->u.s.info; 
    736       e1->u.s.aux = e2->u.s.aux; e1->t = e2->t; 
     734      luaK_concat(fs, &e2->f, e1->f); 
     735      *e1 = *e2; 
    737736      break; 
    738737    } 
     
    740739      lua_assert(e1->f == NO_JUMP);  /* list must be closed */ 
    741740      luaK_dischargevars(fs, e2); 
    742       luaK_concat(fs, &e1->t, e2->t); 
    743       e1->k = e2->k; e1->u.s.info = e2->u.s.info; 
    744       e1->u.s.aux = e2->u.s.aux; e1->f = e2->f; 
     741      luaK_concat(fs, &e2->t, e1->t); 
     742      *e1 = *e2; 
    745743      break; 
    746744    } 
     
    751749        freeexp(fs, e1); 
    752750        SETARG_B(getcode(fs, e2), e1->u.s.info); 
    753         e1->k = e2->k; e1->u.s.info = e2->u.s.info; 
     751        e1->k = VRELOCABLE; e1->u.s.info = e2->u.s.info; 
    754752      } 
    755753      else { 
  • trunk/lib/lua51/lcode.h

    r199 r266  
    3333} BinOpr; 
    3434 
    35 #define binopistest(op) ((op) >= OPR_NE) 
    3635 
    3736typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 
  • trunk/lib/lua51/ldo.c

    r198 r266  
    384384  StkId firstArg = cast(StkId, ud); 
    385385  CallInfo *ci = L->ci; 
    386   if (L->status != LUA_YIELD) {  /* start coroutine */ 
     386  if (L->status == 0) {  /* start coroutine? */ 
    387387    lua_assert(ci == L->base_ci && firstArg > L->base); 
    388388    if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) 
     
    390390  } 
    391391  else {  /* resuming from previous yield */ 
     392    lua_assert(L->status == LUA_YIELD); 
     393    L->status = 0; 
    392394    if (!f_isLua(ci)) {  /* `common' yield? */ 
    393395      /* finish interrupted execution of `OP_CALL' */ 
     
    400402      L->base = L->ci->base; 
    401403  } 
    402   L->status = 0; 
    403404  luaV_execute(L, cast_int(L->ci - L->base_ci)); 
    404405} 
  • trunk/lib/lua51/lgc.c

    r198 r266  
    321321 
    322322 
    323 static void propagateall (global_State *g) { 
    324   while (g->gray) propagatemark(g); 
     323static size_t propagateall (global_State *g) { 
     324  size_t m = 0; 
     325  while (g->gray) m += propagatemark(g); 
     326  return m; 
    325327} 
    326328 
     
    541543  udsize = luaC_separateudata(L, 0);  /* separate userdata to be finalized */ 
    542544  marktmu(g);  /* mark `preserved' userdata */ 
    543   propagateall(g);  /* remark, to propagate `preserveness' */ 
     545  udsize += propagateall(g);  /* remark, to propagate `preserveness' */ 
    544546  cleartable(g->weak);  /* remove collected objects from weak tables */ 
    545547  /* flip current white */ 
     
    591593      if (g->tmudata) { 
    592594        GCTM(L); 
     595        if (g->estimate > GCFINALIZECOST) 
     596          g->estimate -= GCFINALIZECOST; 
    593597        return GCFINALIZECOST; 
    594598      } 
  • trunk/lib/lua51/liolib.c

    r198 r266  
    100100  FILE **p = topfile(L); 
    101101  int ok = lua_pclose(L, *p); 
    102   if (ok) *p = NULL; 
     102  *p = NULL; 
    103103  return pushresult(L, ok, NULL); 
    104104} 
     
    108108  FILE **p = topfile(L); 
    109109  int ok = (fclose(*p) == 0); 
    110   if (ok) *p = NULL; 
     110  *p = NULL; 
    111111  return pushresult(L, ok, NULL); 
    112112} 
  • trunk/lib/lua51/llex.c

    r198 r266  
    2121#include "lstate.h" 
    2222#include "lstring.h" 
     23#include "ltable.h" 
    2324#include "lzio.h" 
    2425 
  • trunk/lib/lua51/llex.h

    r199 r266  
    6969 
    7070LUAI_FUNC void luaX_init (lua_State *L); 
    71 LUAI_FUNC void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, 
     71LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 
    7272                              TString *source); 
    73 LUAI_FUNC TString *luaX_newstring (LexState *LS, const char *str, size_t l); 
     73LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 
    7474LUAI_FUNC void luaX_next (LexState *ls); 
    7575LUAI_FUNC void luaX_lookahead (LexState *ls); 
  • trunk/lib/lua51/loadlib.c

    r198 r266  
    2222#include "lualib.h" 
    2323 
    24  
    25 /* environment variables that hold the search path for packages */ 
    26 #define LUA_PATH        "LUA_PATH" 
    27 #define LUA_CPATH       "LUA_CPATH" 
    2824 
    2925/* prefix for open functions in C libraries */ 
  • trunk/lib/lua51/lopcodes.h

    r199 r266  
    198198OP_FORPREP,/*   A sBx   R(A)-=R(A+2); pc+=sBx                           */ 
    199199 
    200 OP_TFORLOOP,/*  A C     R(A+3), ... ,R(A+3+C) := R(A)(R(A+1), R(A+2));  
    201                         if R(A+3) ~= nil then { pc++; R(A+2)=R(A+3); }        */  
     200OP_TFORLOOP,/*  A C     R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));  
     201                        if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */  
    202202OP_SETLIST,/*   A B C   R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B        */ 
    203203 
  • trunk/lib/lua51/loslib.c

    r198 r266  
    2929  else { 
    3030    lua_pushnil(L); 
    31     if (filename) 
    32       lua_pushfstring(L, "%s: %s", filename, strerror(en)); 
    33     else 
    34       lua_pushfstring(L, "%s", strerror(en)); 
     31    lua_pushfstring(L, "%s: %s", filename, strerror(en)); 
    3532    lua_pushinteger(L, en); 
    3633    return 3; 
     
    127124static int os_date (lua_State *L) { 
    128125  const char *s = luaL_optstring(L, 1, "%c"); 
    129   time_t t = lua_isnoneornil(L, 2) ? time(NULL) : 
    130                                      (time_t)luaL_checknumber(L, 2); 
     126  time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL)); 
    131127  struct tm *stm; 
    132128  if (*s == '!') {  /* UTC? */ 
     
    200196  static const char *const catnames[] = {"all", "collate", "ctype", "monetary", 
    201197     "numeric", "time", NULL}; 
    202   const char *l = lua_tostring(L, 1); 
     198  const char *l = luaL_optstring(L, 1, NULL); 
    203199  int op = luaL_checkoption(L, 2, "all", catnames); 
    204   luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected"); 
    205200  lua_pushstring(L, setlocale(cat[op], l)); 
    206201  return 1; 
  • trunk/lib/lua51/lparser.c

    r198 r266  
    2424#include "lstate.h" 
    2525#include "lstring.h" 
    26  
     26#include "ltable.h" 
    2727 
    2828 
     
    300300  if (bl->upval) 
    301301    luaK_codeABC(fs, OP_CLOSE, bl->nactvar, 0, 0); 
    302   lua_assert(!bl->isbreakable || !bl->upval);  /* loops have no body */ 
     302  /* a block either controls scope or breaks (never both) */ 
     303  lua_assert(!bl->isbreakable || !bl->upval); 
    303304  lua_assert(bl->nactvar == fs->nactvar); 
    304305  fs->freereg = fs->nactvar;  /* free registers */ 
     
    445446  int reg = ls->fs->freereg; 
    446447  expdesc key, val; 
     448  int rkkey; 
    447449  if (ls->t.token == TK_NAME) { 
    448450    luaY_checklimit(fs, cc->nh, MAX_INT, "items in a constructor"); 
     
    453455  cc->nh++; 
    454456  checknext(ls, '='); 
    455   luaK_exp2RK(fs, &key); 
     457  rkkey = luaK_exp2RK(fs, &key); 
    456458  expr(ls, &val); 
    457   luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, luaK_exp2RK(fs, &key), 
    458                                                  luaK_exp2RK(fs, &val)); 
     459  luaK_codeABC(fs, OP_SETTABLE, cc->t->u.s.info, rkkey, luaK_exp2RK(fs, &val)); 
    459460  fs->freereg = reg;  /* free registers */ 
    460461} 
  • trunk/lib/lua51/lparser.h

    r199 r266  
    1010#include "llimits.h" 
    1111#include "lobject.h" 
    12 #include "ltable.h" 
    1312#include "lzio.h" 
    1413 
  • trunk/lib/lua51/lstate.c

    r198 r266  
    199199LUA_API void lua_close (lua_State *L) { 
    200200  L = G(L)->mainthread;  /* only the main thread can be closed */ 
    201   luai_userstateclose(L); 
    202201  lua_lock(L); 
    203202  luaF_close(L, L->stack);  /* close all upvalues for this thread */ 
     
    210209  } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); 
    211210  lua_assert(G(L)->tmudata == NULL); 
     211  luai_userstateclose(L); 
    212212  close_state(L); 
    213213} 
  • trunk/lib/lua51/lstrlib.c

    r198 r266  
    702702        luaL_addchar(b, '\\'); 
    703703        luaL_addchar(b, *s); 
     704        break; 
     705      } 
     706      case '\r': { 
     707        luaL_addlstring(b, "\\r", 2); 
    704708        break; 
    705709      } 
     
    806810        } 
    807811        default: {  /* also treat cases `pnLlh' */ 
    808           return luaL_error(L, "invalid option to " LUA_QL("format")); 
     812          return luaL_error(L, "invalid option " LUA_QL("%%%c") " to " 
     813                               LUA_QL("format"), *(strfrmt - 1)); 
    809814        } 
    810815      } 
  • trunk/lib/lua51/lua.c

    r198 r266  
    108108 
    109109static void print_version (void) { 
    110   l_message(NULL, LUA_VERSION "  " LUA_COPYRIGHT); 
     110  l_message(NULL, LUA_RELEASE "  " LUA_COPYRIGHT); 
    111111} 
    112112 
     
    253253 
    254254 
     255/* check that argument has no extra characters at the end */ 
     256#define notail(x)       {if ((x)[2] != '\0') return -1;} 
     257 
     258 
    255259static int collectargs (char **argv, int *pi, int *pv, int *pe) { 
    256260  int i; 
     
    259263        return i; 
    260264    switch (argv[i][1]) {  /* option */ 
    261       case '-': return (argv[i+1] != NULL ? i+1 : 0); 
    262       case '\0': return i; 
    263       case 'i': *pi = 1;  /* go through */ 
    264       case 'v': *pv = 1; break; 
    265       case 'e': *pe = 1;  /* go through */ 
     265      case '-': 
     266        notail(argv[i]); 
     267        return (argv[i+1] != NULL ? i+1 : 0); 
     268      case '\0': 
     269        return i; 
     270      case 'i': 
     271        notail(argv[i]); 
     272        *pi = 1;  /* go through */ 
     273      case 'v': 
     274        notail(argv[i]); 
     275        *pv = 1; 
     276        break; 
     277      case 'e': 
     278        *pe = 1;  /* go through */ 
    266279      case 'l': 
    267280        if (argv[i][2] == '\0') { 
     
    307320 
    308321static int handle_luainit (lua_State *L) { 
    309   const char *init = getenv("LUA_INIT"); 
     322  const char *init = getenv(LUA_INIT); 
    310323  if (init == NULL) return 0;  /* status OK */ 
    311324  else if (init[0] == '@') 
    312325    return dofile(L, init+1); 
    313326  else 
    314     return dostring(L, init, "=LUA_INIT"); 
     327    return dostring(L, init, "=" LUA_INIT); 
    315328} 
    316329 
  • trunk/lib/lua51/lua.h

    r199 r266  
    1818 
    1919#define LUA_VERSION     "Lua 5.1" 
     20#define LUA_RELEASE     "Lua 5.1.1" 
    2021#define LUA_VERSION_NUM 501 
    2122#define LUA_COPYRIGHT   "Copyright (C) 1994-2006 Lua.org, PUC-Rio" 
  • trunk/lib/lua51/luac.c

    r198 r266  
    7171{ 
    7272 int i; 
     73 int version=0; 
    7374 if (argv[0]!=NULL && *argv[0]!=0) progname=argv[0]; 
    7475 for (i=1; i<argc; i++) 
     
    7980  { 
    8081   ++i; 
     82   if (version) ++version; 
    8183   break; 
    8284  } 
     
    9698   stripping=1; 
    9799  else if (IS("-v"))                    /* show version */ 
    98   { 
    99    printf("%s  %s\n",LUA_VERSION,LUA_COPYRIGHT); 
    100    if (argc==2) exit(EXIT_SUCCESS); 
    101   } 
     100   ++version; 
    102101  else                                  /* unknown option */ 
    103102   usage(argv[i]); 
     
    108107  argv[--i]=Output; 
    109108 } 
     109 if (version) 
     110 { 
     111  printf("%s  %s\n",LUA_RELEASE,LUA_COPYRIGHT); 
     112  if (version==argc-1) exit(EXIT_SUCCESS); 
     113 } 
    110114 return i; 
    111115} 
     
    113117#define toproto(L,i) (clvalue(L->top+(i))->l.p) 
    114118 
    115 static Proto* combine(lua_State* L, int n) 
     119static const Proto* combine(lua_State* L, int n) 
    116120{ 
    117121 if (n==1) 
     
    157161 int argc=s->argc; 
    158162 char** argv=s->argv; 
    159  Proto* f; 
     163 const Proto* f; 
    160164 int i; 
    161165 if (!lua_checkstack(L,argc)) fatal("too many input files"); 
  • trunk/lib/lua51/luaconf.h

    r199 r266  
    5858#define LUA_USE_ULONGJMP 
    5959#endif 
     60 
     61 
     62/* 
     63@@ LUA_PATH and LUA_CPATH are the names of the environment variables that 
     64@* Lua check to set its paths. 
     65@@ LUA_INIT is the name of the environment variable that Lua 
     66@* checks for initialization code. 
     67** CHANGE them if you want different names. 
     68*/ 
     69#define LUA_PATH        "LUA_PATH" 
     70#define LUA_CPATH       "LUA_CPATH" 
     71#define LUA_INIT        "LUA_INIT" 
    6072 
    6173 
     
    231243** prompts dynamically, assigning to globals _PROMPT/_PROMPT2.) 
    232244*/ 
    233 #define LUA_PROMPT              ">:
    234 #define LUA_PROMPT2             ">>:
     245#define LUA_PROMPT              ">
     246#define LUA_PROMPT2             ">>
    235247 
    236248 
     
    322334** access vararg parameters (instead of the old 'arg' table). 
    323335*/ 
    324 #undef LUA_COMPAT_VARARG 
     336#define LUA_COMPAT_VARARG 
    325337 
    326338/* 
     
    329341** the new '%' operator instead of 'math.mod'. 
    330342*/ 
    331 #undef LUA_COMPAT_MOD 
     343#define LUA_COMPAT_MOD 
    332344 
    333345/* 
     
    337349** off the advisory error when nesting [[...]]. 
    338350*/ 
    339 #undef LUA_COMPAT_LSTR 
     351#define LUA_COMPAT_LSTR                1 
    340352 
    341353/* 
     
    344356** 'string.gmatch'. 
    345357*/ 
    346 #undef LUA_COMPAT_GFIND 
     358#define LUA_COMPAT_GFIND 
    347359 
    348360/* 
     
    352364** your uses of 'luaL_openlib' 
    353365*/ 
    354 #undef LUA_COMPAT_OPENLIB 
     366#define LUA_COMPAT_OPENLIB 
    355367 
    356368 
     
    489501*/ 
    490502 
    491 /*#define LUA_NUMBER_DOUBLE */ 
    492 #define LUA_NUMBER      long 
     503#define LUA_NUMBER_DOUBLE 
     504#define LUA_NUMBER      double 
    493505 
    494506/* 
     
    496508@* over a number. 
    497509*/ 
    498 #define LUAI_UACNUMBER  long 
     510#define LUAI_UACNUMBER  double 
    499511 
    500512 
     
    506518@@ lua_str2number converts a string to a number. 
    507519*/ 
    508 #define LUA_NUMBER_SCAN         "%ld
    509 #define LUA_NUMBER_FMT          "%ld
     520#define LUA_NUMBER_SCAN         "%lf
     521#define LUA_NUMBER_FMT          "%.14g
    510522#define lua_number2str(s,n)     sprintf((s), LUA_NUMBER_FMT, (n)) 
    511523#define LUAI_MAXNUMBER2STR      32 /* 16 digits, sign, point, and \0 */ 
    512 #define lua_str2number(s,p)     strtol((s), (p), 10
     524#define lua_str2number(s,p)     strtod((s), (p)
    513525 
    514526 
     
    518530#if defined(LUA_CORE) 
    519531#include <math.h> 
    520 #include "lpow.h" 
    521532#define luai_numadd(a,b)        ((a)+(b)) 
    522533#define luai_numsub(a,b)        ((a)-(b)) 
    523534#define luai_nummul(a,b)        ((a)*(b)) 
    524535#define luai_numdiv(a,b)        ((a)/(b)) 
    525 #define luai_nummod(a,b)        ((a)%(b)) 
    526 #define luai_numpow(a,b)        (lpow(a,b)) 
     536#define luai_nummod(a,b)        ((a) - floor((a)/(b))*(b)) 
     537#define luai_numpow(a,b)        (pow(a,b)) 
    527538#define luai_numunm(a)          (-(a)) 
    528539#define luai_numeq(a,b)         ((a)==(b)) 
    529540#define luai_numlt(a,b)         ((a)<(b)) 
    530541#define luai_numle(a,b)         ((a)<=(b)) 
    531 #define luai_numisnan(a)        (0
     542#define luai_numisnan(a)        (!luai_numeq((a), (a))
    532543#endif 
    533544 
     
    545556#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) && !defined(__SSE2__) && \ 
    546557    (defined(__i386) || defined (_M_IX86) || defined(__i386__)) 
     558 
     559/* On a Microsoft compiler, use assembler */ 
     560#if defined(_MSC_VER) 
     561 
     562#define lua_number2int(i,d)   __asm fld d   __asm fistp i 
     563#define lua_number2integer(i,n)         lua_number2int(i, n) 
     564 
     565/* the next trick should work on any Pentium, but sometimes clashes 
     566   with a DirectX idiosyncrasy */ 
     567#else 
     568 
    547569union luai_Cast { double l_d; long l_l; }; 
    548570#define lua_number2int(i,d) \ 
    549571  { volatile union luai_Cast u; u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } 
    550572#define lua_number2integer(i,n)         lua_number2int(i, n) 
     573 
     574#endif 
     575 
    551576 
    552577/* this option always works, but may be slow */ 
  • trunk/lib/lua51/lvm.c

    r198 r266  
    377377  const Instruction *pc; 
    378378 reentry:  /* entry point */ 
     379  lua_assert(isLua(L->ci)); 
    379380  pc = L->savedpc; 
    380381  cl = &clvalue(L->ci->func)->l; 
  • trunk/lib/lua51/print.c

    r198 r266  
    2121#define VOID(p)         ((const void*)(p)) 
    2222 
    23 static void PrintString(const Proto* f, int n) 
    24 
    25  const char* s=svalue(&f->k[n]); 
     23static void PrintString(const TString* ts) 
     24
     25 const char* s=getstr(ts); 
     26 int n=ts->tsv.len; 
     27 int i; 
    2628 putchar('"'); 
    27  for (; *s; s++) 
    28  { 
    29   switch (*s) 
     29 for (i=0; i<n; i++) 
     30 { 
     31  int c=s[i]; 
     32  switch (c) 
    3033  { 
    3134   case '"': printf("\\\""); break; 
     
    3740   case '\t': printf("\\t"); break; 
    3841   case '\v': printf("\\v"); break; 
    39    default:     if (isprint((unsigned char)*s)) 
    40                         printf("%c",*s); 
     42   default:     if (isprint((unsigned char)c)) 
     43                        putchar(c); 
    4144                else 
    42                         printf("\\%03u",(unsigned char)*s); 
     45                        printf("\\%03u",(unsigned char)c); 
    4346  } 
    4447 } 
     
    6164        break; 
    6265  case LUA_TSTRING: 
    63         PrintString(f,i); 
     66        PrintString(rawtsvalue(o)); 
    6467        break; 
    6568  default:                              /* cannot happen */