lua_Number defined in lua.h (1st version)

This commit is contained in:
Roberto Ierusalimschy 2000-12-04 16:33:40 -02:00
parent 10ac68c648
commit 4894c27962
19 changed files with 67 additions and 74 deletions

8
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.110 2000/10/30 12:50:09 roberto Exp roberto $
** $Id: lapi.c,v 1.111 2000/11/24 17:39:56 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -154,7 +154,7 @@ LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
LUA_API double lua_tonumber (lua_State *L, int index) {
LUA_API lua_Number lua_tonumber (lua_State *L, int index) {
StkId o = luaA_indexAcceptable(L, index);
return (o == NULL || tonumber(o)) ? 0 : nvalue(o);
}
@ -205,7 +205,7 @@ LUA_API void lua_pushnil (lua_State *L) {
}
LUA_API void lua_pushnumber (lua_State *L, double n) {
LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
nvalue(L->top) = n;
ttype(L->top) = LUA_TNUMBER;
api_incr_top(L);
@ -461,7 +461,7 @@ LUA_API int lua_getn (lua_State *L, int index) {
if (ttype(value) == LUA_TNUMBER)
return (int)nvalue(value);
else {
Number max = 0;
lua_Number max = 0;
int i = h->size;
Node *n = h->node;
while (i--) {

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.42 2000/10/30 12:38:50 roberto Exp roberto $
** $Id: lauxlib.c,v 1.43 2000/10/30 13:07:48 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -84,15 +84,15 @@ LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, s
}
LUALIB_API double luaL_check_number (lua_State *L, int narg) {
double d = lua_tonumber(L, narg);
LUALIB_API lua_Number luaL_check_number (lua_State *L, int narg) {
lua_Number d = lua_tonumber(L, narg);
if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
type_error(L, narg, LUA_TNUMBER);
return d;
}
LUALIB_API double luaL_opt_number (lua_State *L, int narg, double def) {
LUALIB_API lua_Number luaL_opt_number (lua_State *L, int narg, lua_Number def) {
if (lua_isnull(L, narg)) return def;
else return luaL_check_number(L, narg);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.29 2000/10/27 16:15:53 roberto Exp roberto $
** $Id: lauxlib.h,v 1.30 2000/10/30 12:38:50 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -30,8 +30,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n);
LUALIB_API void luaL_argerror (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def, size_t *len);
LUALIB_API double luaL_check_number (lua_State *L, int numArg);
LUALIB_API double luaL_opt_number (lua_State *L, int numArg, double def);
LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg);
LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def);
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg);
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);

10
lcode.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 1.51 2000/09/29 12:42:13 roberto Exp roberto $
** $Id: lcode.c,v 1.52 2000/11/30 18:50:47 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -99,7 +99,7 @@ void luaK_kstr (LexState *ls, int c) {
}
static int number_constant (FuncState *fs, Number r) {
static int number_constant (FuncState *fs, lua_Number r) {
/* check whether `r' has appeared within the last LOOKBACKNUMS entries */
Proto *f = fs->f;
int c = f->nknum;
@ -107,7 +107,7 @@ static int number_constant (FuncState *fs, Number r) {
while (--c >= lim)
if (f->knum[c] == r) return c;
/* not found; create a new entry */
luaM_growvector(fs->L, f->knum, f->nknum, 1, Number,
luaM_growvector(fs->L, f->knum, f->nknum, 1, lua_Number,
"constant table overflow", MAXARG_U);
c = f->nknum++;
f->knum[c] = r;
@ -115,8 +115,8 @@ static int number_constant (FuncState *fs, Number r) {
}
void luaK_number (FuncState *fs, Number f) {
if (f <= (Number)MAXARG_S && (Number)(int)f == f)
void luaK_number (FuncState *fs, lua_Number f) {
if (f <= (lua_Number)MAXARG_S && (lua_Number)(int)f == f)
luaK_code1(fs, OP_PUSHINT, (int)f); /* f has a short integer value */
else
luaK_code1(fs, OP_PUSHNUM, number_constant(fs, f));

View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.h,v 1.16 2000/08/09 14:49:13 roberto Exp roberto $
** $Id: lcode.h,v 1.17 2000/11/30 18:50:47 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -58,7 +58,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *v, int keepvalue);
int luaK_getlabel (FuncState *fs);
void luaK_deltastack (FuncState *fs, int delta);
void luaK_kstr (LexState *ls, int c);
void luaK_number (FuncState *fs, Number f);
void luaK_number (FuncState *fs, lua_Number f);
void luaK_adjuststack (FuncState *fs, int n);
int luaK_lastisopen (FuncState *fs);
void luaK_setcallreturns (FuncState *fs, int nresults);

View File

@ -1,5 +1,5 @@
/*
** $Id: lfunc.c,v 1.33 2000/10/18 17:19:09 roberto Exp roberto $
** $Id: lfunc.c,v 1.34 2000/10/30 12:20:29 roberto Exp roberto $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/
@ -57,7 +57,7 @@ Proto *luaF_newproto (lua_State *L) {
static size_t protosize (Proto *f) {
return sizeof(Proto)
+ f->nknum*sizeof(Number)
+ f->nknum*sizeof(lua_Number)
+ f->nkstr*sizeof(TString *)
+ f->nkproto*sizeof(Proto *)
+ f->ncode*sizeof(Instruction)

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.91 2000/10/31 13:10:24 roberto Exp roberto $
** $Id: liolib.c,v 1.92 2000/11/23 13:49:35 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -476,7 +476,7 @@ static int io_getenv (lua_State *L) {
static int io_clock (lua_State *L) {
lua_pushnumber(L, ((double)clock())/CLOCKS_PER_SEC);
lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC);
return 1;
}

4
llex.h
View File

@ -1,5 +1,5 @@
/*
** $Id: llex.h,v 1.30 2000/06/21 18:13:56 roberto Exp roberto $
** $Id: llex.h,v 1.31 2000/09/27 17:41:58 roberto Exp roberto $
** Lexical Analyzer
** See Copyright Notice in lua.h
*/
@ -36,7 +36,7 @@ enum RESERVED {
typedef union {
Number r;
lua_Number r;
TString *ts;
} SemInfo; /* semantics information */

View File

@ -1,5 +1,5 @@
/*
** $Id: llimits.h,v 1.19 2000/10/26 12:47:05 roberto Exp roberto $
** $Id: llimits.h,v 1.20 2000/11/24 17:39:56 roberto Exp roberto $
** Limits, basic types, and some other "installation-dependent" definitions
** See Copyright Notice in lua.h
*/
@ -31,21 +31,11 @@
#endif
/*
** Define the type `number' of Lua
** GREP LUA_NUMBER to change that
*/
#ifndef LUA_NUM_TYPE
#define LUA_NUM_TYPE double
#endif
typedef LUA_NUM_TYPE Number;
/* function to convert a Number to a string */
/* function to convert a lua_Number to a string */
#define NUMBER_FMT "%.16g" /* LUA_NUMBER */
#define lua_number2str(s,n) sprintf((s), NUMBER_FMT, (n))
/* function to convert a string to a Number */
/* function to convert a string to a lua_Number */
#define lua_str2number(s,p) strtod((s), (p))

View File

@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.31 2000/10/27 16:15:53 roberto Exp roberto $
** $Id: lmathlib.c,v 1.32 2000/10/31 13:10:24 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@ -139,10 +139,10 @@ static int math_ldexp (lua_State *L) {
static int math_min (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
double dmin = luaL_check_number(L, 1);
lua_Number dmin = luaL_check_number(L, 1);
int i;
for (i=2; i<=n; i++) {
double d = luaL_check_number(L, i);
lua_Number d = luaL_check_number(L, i);
if (d < dmin)
dmin = d;
}
@ -153,10 +153,10 @@ static int math_min (lua_State *L) {
static int math_max (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
double dmax = luaL_check_number(L, 1);
lua_Number dmax = luaL_check_number(L, 1);
int i;
for (i=2; i<=n; i++) {
double d = luaL_check_number(L, i);
lua_Number d = luaL_check_number(L, i);
if (d > dmax)
dmax = d;
}
@ -168,7 +168,7 @@ static int math_max (lua_State *L) {
static int math_random (lua_State *L) {
/* the '%' avoids the (rare) case of r==1, and is needed also because on
some systems (SunOS!) "rand()" may return a value larger than RAND_MAX */
double r = (double)(rand()%RAND_MAX) / (double)RAND_MAX;
lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
switch (lua_gettop(L)) { /* check number of arguments */
case 0: { /* no arguments */
lua_pushnumber(L, r); /* Number between 0 and 1 */

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 1.55 2000/10/20 16:36:32 roberto Exp roberto $
** $Id: lobject.c,v 1.56 2000/11/24 17:39:56 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -65,9 +65,9 @@ char *luaO_openspace (lua_State *L, size_t n) {
}
int luaO_str2d (const char *s, Number *result) { /* LUA_NUMBER */
int luaO_str2d (const char *s, lua_Number *result) { /* LUA_NUMBER */
char *endptr;
Number res = lua_str2number(s, &endptr);
lua_Number res = lua_str2number(s, &endptr);
if (endptr == s) return 0; /* no conversion */
while (isspace((unsigned char)*endptr)) endptr++;
if (*endptr != '\0') return 0; /* invalid trailing characters? */

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 1.82 2000/10/30 17:49:19 roberto Exp roberto $
** $Id: lobject.h,v 1.83 2000/11/24 17:39:56 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -48,7 +48,7 @@ typedef union {
struct Closure *cl; /* LUA_TFUNCTION */
struct Hash *a; /* LUA_TTABLE */
struct CallInfo *i; /* LUA_TLMARK */
Number n; /* LUA_TNUMBER */
lua_Number n; /* LUA_TNUMBER */
} Value;
@ -101,7 +101,7 @@ typedef struct TString {
** Function Prototypes
*/
typedef struct Proto {
Number *knum; /* Number numbers used by the function */
lua_Number *knum; /* numbers used by the function */
int nknum; /* size of `knum' */
struct TString **kstr; /* strings used by the function */
int nkstr; /* size of `kstr' */
@ -195,7 +195,7 @@ luint32 luaO_power2 (luint32 n);
char *luaO_openspace (lua_State *L, size_t n);
int luaO_equalObj (const TObject *t1, const TObject *t2);
int luaO_str2d (const char *s, Number *result);
int luaO_str2d (const char *s, lua_Number *result);
void luaO_verror (lua_State *L, const char *fmt, ...);
void luaO_chunkid (char *out, const char *source, int len);

View File

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.67 2000/08/29 14:48:16 roberto Exp roberto $
** $Id: lopcodes.h,v 1.68 2000/10/24 16:05:59 roberto Exp roberto $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -91,7 +91,7 @@ OP_TAILCALL,/* A B v_n-v_1 f(at a) (return) f(v1,...,v_n) */
OP_PUSHNIL,/* U - nil_1-nil_u */
OP_POP,/* U a_u-a_1 - */
OP_PUSHINT,/* S - (Number)s */
OP_PUSHINT,/* S - (lua_Number)s */
OP_PUSHSTRING,/* K - KSTR[k] */
OP_PUSHNUM,/* N - KNUM[n] */
OP_PUSHNEGNUM,/* N - -KNUM[n] */

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 1.117 2000/11/29 11:57:42 roberto Exp roberto $
** $Id: lparser.c,v 1.118 2000/11/30 18:50:47 roberto Exp roberto $
** LL(1) Parser and code generator for Lua
** See Copyright Notice in lua.h
*/
@ -332,7 +332,7 @@ static void close_func (LexState *ls) {
luaK_getlabel(fs); /* close eventual list of pending jumps */
luaM_reallocvector(L, f->code, fs->pc, Instruction);
luaM_reallocvector(L, f->kstr, f->nkstr, TString *);
luaM_reallocvector(L, f->knum, f->nknum, Number);
luaM_reallocvector(L, f->knum, f->nknum, lua_Number);
luaM_reallocvector(L, f->kproto, f->nkproto, Proto *);
removelocalvars(ls, fs->nactloc);
luaM_reallocvector(L, f->locvars, f->nlocvars, LocVar);
@ -608,7 +608,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
FuncState *fs = ls->fs;
switch (ls->t.token) {
case TK_NUMBER: { /* simpleexp -> NUMBER */
Number r = ls->t.seminfo.r;
lua_Number r = ls->t.seminfo.r;
next(ls);
luaK_number(fs, r);
break;

View File

@ -1,5 +1,5 @@
/*
** $Id: ltable.c,v 1.58 2000/10/26 12:47:05 roberto Exp roberto $
** $Id: ltable.c,v 1.59 2000/11/24 17:39:56 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -81,7 +81,7 @@ static const TObject *luaH_getany (lua_State *L, const Hash *t,
/* specialized version for numbers */
const TObject *luaH_getnum (const Hash *t, Number key) {
const TObject *luaH_getnum (const Hash *t, lua_Number key) {
Node *n = &t->node[(luint32)(lint32)key&(t->size-1)];
do {
if (ttype(&n->key) == LUA_TNUMBER && nvalue(&n->key) == key)
@ -290,7 +290,7 @@ TObject *luaH_setint (lua_State *L, Hash *t, int key) {
}
void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val) {
void luaH_setstrnum (lua_State *L, Hash *t, TString *key, lua_Number val) {
TObject *value, index;
ttype(&index) = LUA_TSTRING;
tsvalue(&index) = key;

View File

@ -1,5 +1,5 @@
/*
** $Id: ltable.h,v 1.24 2000/08/31 14:08:27 roberto Exp roberto $
** $Id: ltable.h,v 1.25 2000/11/24 17:39:56 roberto Exp roberto $
** Lua tables (hash)
** See Copyright Notice in lua.h
*/
@ -17,13 +17,13 @@
Hash *luaH_new (lua_State *L, int nhash);
void luaH_free (lua_State *L, Hash *t);
const TObject *luaH_get (lua_State *L, const Hash *t, const TObject *key);
const TObject *luaH_getnum (const Hash *t, Number key);
const TObject *luaH_getnum (const Hash *t, lua_Number key);
const TObject *luaH_getstr (const Hash *t, TString *key);
void luaH_remove (Hash *t, TObject *key);
TObject *luaH_set (lua_State *L, Hash *t, const TObject *key);
Node * luaH_next (lua_State *L, const Hash *t, const TObject *r);
TObject *luaH_setint (lua_State *L, Hash *t, int key);
void luaH_setstrnum (lua_State *L, Hash *t, TString *key, Number val);
void luaH_setstrnum (lua_State *L, Hash *t, TString *key, lua_Number val);
luint32 luaH_hash (lua_State *L, const TObject *key);
const TObject *luaH_getglobal (lua_State *L, const char *name);

9
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.78 2000/10/30 12:38:50 roberto Exp roberto $
** $Id: lua.h,v 1.79 2000/10/31 12:44:07 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: lua@tecgraf.puc-rio.br
@ -57,6 +57,9 @@
#define LUA_ERRERR 5
/* Lua numerical type */
typedef double lua_Number;
typedef struct lua_State lua_State;
typedef int (*lua_CFunction) (lua_State *L);
@ -107,7 +110,7 @@ LUA_API int lua_tag (lua_State *L, int index);
LUA_API int lua_equal (lua_State *L, int index1, int index2);
LUA_API int lua_lessthan (lua_State *L, int index1, int index2);
LUA_API double lua_tonumber (lua_State *L, int index);
LUA_API lua_Number lua_tonumber (lua_State *L, int index);
LUA_API const char *lua_tostring (lua_State *L, int index);
LUA_API size_t lua_strlen (lua_State *L, int index);
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int index);
@ -119,7 +122,7 @@ LUA_API const void *lua_topointer (lua_State *L, int index);
** push functions (C -> stack)
*/
LUA_API void lua_pushnil (lua_State *L);
LUA_API void lua_pushnumber (lua_State *L, double n);
LUA_API void lua_pushnumber (lua_State *L, lua_Number n);
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len);
LUA_API void lua_pushstring (lua_State *L, const char *s);
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);

View File

@ -1,5 +1,5 @@
/*
** $Id: lundump.c,v 1.33 2000/10/31 16:57:23 lhf Exp $
** $Id: lundump.c,v 1.34 2000/11/07 12:44:44 roberto Exp roberto $
** load bytecodes from files
** See Copyright Notice in lua.h
*/
@ -82,9 +82,9 @@ static size_t LoadSize (lua_State* L, ZIO* Z, int swap)
return x;
}
static Number LoadNumber (lua_State* L, ZIO* Z, int swap)
static lua_Number LoadNumber (lua_State* L, ZIO* Z, int swap)
{
Number x;
lua_Number x;
LoadBlock(L,&x,sizeof(x),Z,swap);
return x;
}
@ -142,7 +142,7 @@ static void LoadConstants (lua_State* L, Proto* tf, ZIO* Z, int swap)
for (i=0; i<n; i++)
tf->kstr[i]=LoadString(L,Z,swap);
tf->nknum=n=LoadInt(L,Z,swap);
tf->knum=luaM_newvector(L,n,Number);
tf->knum=luaM_newvector(L,n,lua_Number);
LoadVector(L,tf->knum,n,sizeof(*tf->knum),Z,swap);
tf->nkproto=n=LoadInt(L,Z,swap);
tf->kproto=luaM_newvector(L,n,Proto*);
@ -187,7 +187,7 @@ static void TestSize (lua_State* L, int s, const char* what, ZIO* Z)
static int LoadHeader (lua_State* L, ZIO* Z)
{
int version,swap;
Number f=0,tf=TEST_NUMBER;
lua_Number f=0,tf=TEST_NUMBER;
LoadSignature(L,Z);
version=ezgetc(L,Z);
if (version>VERSION)
@ -205,7 +205,7 @@ static int LoadHeader (lua_State* L, ZIO* Z)
TESTSIZE(SIZE_INSTRUCTION);
TESTSIZE(SIZE_OP);
TESTSIZE(SIZE_B);
TESTSIZE(sizeof(Number));
TESTSIZE(sizeof(lua_Number));
f=LoadNumber(L,Z,swap);
if ((long)f!=(long)tf) /* disregard errors in last bit of fraction */
luaO_verror(L,"unknown number format in `%.99s':\n"

8
lvm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 1.146 2000/10/26 12:47:05 roberto Exp roberto $
** $Id: lvm.c,v 1.147 2000/11/24 17:39:56 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -402,7 +402,7 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
}
case OP_PUSHINT: {
ttype(top) = LUA_TNUMBER;
nvalue(top) = (Number)GETARG_S(i);
nvalue(top) = (lua_Number)GETARG_S(i);
top++;
break;
}
@ -523,11 +523,11 @@ StkId luaV_execute (lua_State *L, const Closure *cl, StkId base) {
case OP_ADDI: {
if (tonumber(top-1)) {
ttype(top) = LUA_TNUMBER;
nvalue(top) = (Number)GETARG_S(i);
nvalue(top) = (lua_Number)GETARG_S(i);
call_arith(L, top+1, TM_ADD);
}
else
nvalue(top-1) += (Number)GETARG_S(i);
nvalue(top-1) += (lua_Number)GETARG_S(i);
break;
}
case OP_SUB: {