new API function `lua_type' + new type lua_Type

This commit is contained in:
Roberto Ierusalimschy 2000-10-02 17:10:55 -03:00
parent 78bc8e553d
commit f6834f4393
15 changed files with 125 additions and 102 deletions

21
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.101 2000/09/29 12:42:13 roberto Exp roberto $
** $Id: lapi.c,v 1.102 2000/10/02 14:47:43 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -116,8 +116,16 @@ void lua_pushvalue (lua_State *L, int index) {
return ((test) ? (value) : (default)); }
const char *lua_type (lua_State *L, int index) {
btest(L, index, luaO_typename(o), "NO VALUE");
lua_Type lua_type (lua_State *L, int index) {
btest(L, index, luaO_type(o), LUA_NOVALUE);
}
const char *lua_typename (lua_State *L, lua_Type t) {
static const char *const names[] = {
"NO VALUE", "userdata", "number", "string", "table", "function", "nil"
};
UNUSED(L);
return names[(int)t];
}
int lua_iscfunction (lua_State *L, int index) {
@ -128,6 +136,11 @@ int lua_isnumber (lua_State *L, int index) {
btest(L, index, (tonumber(Index(L, index)) == 0), 0);
}
int lua_isstring (lua_State *L, int index) {
lua_Type t = lua_type(L, index);
return (t == LUA_TSTRING || t == LUA_TNUMBER);
}
int lua_tag (lua_State *L, int index) {
btest(L, index,
((ttype(o) == TAG_USERDATA) ? tsvalue(o)->u.d.tag :
@ -411,7 +424,7 @@ void lua_settag (lua_State *L, int tag) {
break;
default:
luaO_verror(L, "cannot change the tag of a %.20s",
luaO_typename(L->top-1));
luaO_typename(L, L->top-1));
}
L->top--;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.36 2000/09/12 13:48:22 roberto Exp roberto $
** $Id: lauxlib.c,v 1.37 2000/09/29 12:40:56 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -40,11 +40,11 @@ void luaL_argerror (lua_State *L, int narg, const char *extramsg) {
}
static void type_error (lua_State *L, int narg, const char *type_name) {
static void type_error (lua_State *L, int narg, lua_Type t) {
char buff[100];
const char *rt = lua_type(L, narg);
const char *rt = lua_typename(L, lua_type(L, narg));
if (*rt == 'N') rt = "no value";
sprintf(buff, "%.10s expected, got %.10s", type_name, rt);
sprintf(buff, "%.10s expected, got %.10s", lua_typename(L, t), rt);
luaL_argerror(L, narg, buff);
}
@ -55,20 +55,21 @@ void luaL_checkstack (lua_State *L, int space, const char *mes) {
}
/*
** use the 3rd letter of type names for testing:
** nuMber, niL, stRing, fuNction, usErdata, taBle, anY
*/
void luaL_checktype(lua_State *L, int narg, const char *tname) {
const char *rt = lua_type(L, narg);
if (!(*rt != 'N' && (tname[2] == 'y' || tname[2] == rt[2])))
type_error(L, narg, tname);
void luaL_checktype(lua_State *L, int narg, lua_Type t) {
if (lua_type(L, narg) != t)
type_error(L, narg, t);
}
void luaL_checkany (lua_State *L, int narg) {
if (lua_type(L, narg) == LUA_NOVALUE)
luaL_argerror(L, narg, "value expected");
}
const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
const char *s = lua_tostring(L, narg);
if (!s) type_error(L, narg, "string");
if (!s) type_error(L, narg, LUA_TSTRING);
if (len) *len = lua_strlen(L, narg);
return s;
}
@ -88,7 +89,7 @@ const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
double luaL_check_number (lua_State *L, int narg) {
double d = lua_tonumber(L, narg);
if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
type_error(L, narg, "number");
type_error(L, narg, LUA_TNUMBER);
return d;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.24 2000/09/11 20:29:27 roberto Exp roberto $
** $Id: lauxlib.h,v 1.25 2000/09/12 13:48:22 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -30,7 +30,8 @@ double luaL_check_number (lua_State *L, int numArg);
double luaL_opt_number (lua_State *L, int numArg, double def);
void luaL_checkstack (lua_State *L, int space, const char *msg);
void luaL_checktype (lua_State *L, int narg, const char *tname);
void luaL_checktype (lua_State *L, int narg, lua_Type t);
void luaL_checkany (lua_State *L, int narg);
void luaL_verror (lua_State *L, const char *fmt, ...);
int luaL_findstring (const char *name, const char *const list[]);

View File

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.6 2000/09/20 12:54:17 roberto Exp roberto $
** $Id: lbaselib.c,v 1.7 2000/10/02 14:47:43 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -34,7 +34,7 @@ static int luaB__ALERT (lua_State *L) {
** The library `liolib' redefines _ERRORMESSAGE for better error information.
*/
static int luaB__ERRORMESSAGE (lua_State *L) {
luaL_checktype(L, 1, "string");
luaL_checktype(L, 1, LUA_TSTRING);
lua_getglobal(L, LUA_ALERT);
if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
lua_Debug ar;
@ -87,7 +87,7 @@ static int luaB_print (lua_State *L) {
static int luaB_tonumber (lua_State *L) {
int base = luaL_opt_int(L, 2, 10);
if (base == 10) { /* standard conversion */
luaL_checktype(L, 1, "any");
luaL_checkany(L, 1);
if (lua_isnumber(L, 1)) {
lua_pushnumber(L, lua_tonumber(L, 1));
return 1;
@ -118,7 +118,7 @@ static int luaB_error (lua_State *L) {
}
static int luaB_setglobal (lua_State *L) {
luaL_checktype(L, 2, "any");
luaL_checkany(L, 2);
lua_setglobal(L, luaL_check_string(L, 1));
return 0;
}
@ -129,13 +129,13 @@ static int luaB_getglobal (lua_State *L) {
}
static int luaB_tag (lua_State *L) {
luaL_checktype(L, 1, "any");
luaL_checkany(L, 1);
lua_pushnumber(L, lua_tag(L, 1));
return 1;
}
static int luaB_settag (lua_State *L) {
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
lua_pushvalue(L, 1); /* push table */
lua_settag(L, luaL_check_int(L, 2));
lua_pop(L, 1); /* remove second argument */
@ -156,7 +156,7 @@ static int luaB_copytagmethods (lua_State *L) {
static int luaB_globals (lua_State *L) {
lua_getglobals(L); /* value to be returned */
if (!lua_isnull(L, 1)) {
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
lua_pushvalue(L, 1); /* new table of globals */
lua_setglobals(L);
}
@ -164,16 +164,16 @@ static int luaB_globals (lua_State *L) {
}
static int luaB_rawget (lua_State *L) {
luaL_checktype(L, 1, "table");
luaL_checktype(L, 2, "any");
luaL_checktype(L, 1, LUA_TTABLE);
luaL_checkany(L, 2);
lua_rawget(L, -2);
return 1;
}
static int luaB_rawset (lua_State *L) {
luaL_checktype(L, 1, "table");
luaL_checktype(L, 2, "any");
luaL_checktype(L, 3, "any");
luaL_checktype(L, 1, LUA_TTABLE);
luaL_checkany(L, 2);
luaL_checkany(L, 3);
lua_rawset(L, -3);
return 1;
}
@ -209,14 +209,14 @@ static int luaB_collectgarbage (lua_State *L) {
static int luaB_type (lua_State *L) {
luaL_checktype(L, 1, "any");
lua_pushstring(L, lua_type(L, 1));
luaL_checkany(L, 1);
lua_pushstring(L, lua_typename(L, lua_type(L, 1)));
return 1;
}
static int luaB_next (lua_State *L) {
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
lua_settop(L, 2); /* create a 2nd argument if there isn't one */
if (lua_next(L, 1))
return 2;
@ -269,7 +269,7 @@ static int luaB_call (lua_State *L) {
int err = 0; /* index of old error method */
int i, status;
int n;
luaL_checktype(L, 2, "table");
luaL_checktype(L, 2, LUA_TTABLE);
n = lua_getn(L, 2);
if (!lua_isnull(L, 4)) { /* set new error method */
lua_getglobal(L, LUA_ERRORMESSAGE);
@ -303,26 +303,26 @@ static int luaB_call (lua_State *L) {
static int luaB_tostring (lua_State *L) {
char buff[64];
switch (lua_type(L, 1)[2]) {
case 'm': /* nuMber */
switch (lua_type(L, 1)) {
case LUA_TNUMBER:
lua_pushstring(L, lua_tostring(L, 1));
return 1;
case 'r': /* stRing */
case LUA_TSTRING:
lua_pushvalue(L, 1);
return 1;
case 'b': /* taBle */
case LUA_TTABLE:
sprintf(buff, "table: %p", lua_topointer(L, 1));
break;
case 'n': /* fuNction */
case LUA_TFUNCTION:
sprintf(buff, "function: %p", lua_topointer(L, 1));
break;
case 'e': /* usErdata */
case LUA_TUSERDATA:
sprintf(buff, "userdata(%d): %p", lua_tag(L, 1), lua_touserdata(L, 1));
break;
case 'l': /* niL */
case LUA_TNIL:
lua_pushstring(L, "nil");
return 1;
default:
case LUA_NOVALUE:
luaL_argerror(L, 1, "value expected");
}
lua_pushstring(L, buff);
@ -332,8 +332,8 @@ static int luaB_tostring (lua_State *L) {
static int luaB_foreachi (lua_State *L) {
int n, i;
luaL_checktype(L, 1, "table");
luaL_checktype(L, 2, "function");
luaL_checktype(L, 1, LUA_TTABLE);
luaL_checktype(L, 2, LUA_TFUNCTION);
n = lua_getn(L, 1);
for (i=1; i<=n; i++) {
lua_pushvalue(L, 2); /* function */
@ -349,8 +349,8 @@ static int luaB_foreachi (lua_State *L) {
static int luaB_foreach (lua_State *L) {
luaL_checktype(L, 1, "table");
luaL_checktype(L, 2, "function");
luaL_checktype(L, 1, LUA_TTABLE);
luaL_checktype(L, 2, LUA_TFUNCTION);
lua_pushnil(L); /* first index */
for (;;) {
if (lua_next(L, 1) == 0)
@ -367,7 +367,7 @@ static int luaB_foreach (lua_State *L) {
static int luaB_assert (lua_State *L) {
luaL_checktype(L, 1, "any");
luaL_checkany(L, 1);
if (lua_isnil(L, 1))
luaL_verror(L, "assertion failed! %.90s", luaL_opt_string(L, 2, ""));
return 0;
@ -375,7 +375,7 @@ static int luaB_assert (lua_State *L) {
static int luaB_getn (lua_State *L) {
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
lua_pushnumber(L, lua_getn(L, 1));
return 1;
}
@ -384,7 +384,7 @@ static int luaB_getn (lua_State *L) {
static int luaB_tinsert (lua_State *L) {
int v = lua_gettop(L); /* last argument: to be inserted */
int n, pos;
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
n = lua_getn(L, 1);
if (v == 2) /* called with only 2 arguments */
pos = n+1;
@ -405,7 +405,7 @@ static int luaB_tinsert (lua_State *L) {
static int luaB_tremove (lua_State *L) {
int pos, n;
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
n = lua_getn(L, 1);
pos = luaL_opt_int(L, 2, n);
if (n <= 0) return 0; /* table is "empty" */
@ -517,10 +517,10 @@ static void auxsort (lua_State *L, int l, int u) {
static int luaB_sort (lua_State *L) {
int n;
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
n = lua_getn(L, 1);
if (!lua_isnull(L, 2)) /* is there a 2nd argument? */
luaL_checktype(L, 2, "function");
luaL_checktype(L, 2, LUA_TFUNCTION);
lua_settop(L, 2); /* make sure there is two arguments */
auxsort(L, 1, n);
return 0;

View File

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.20 2000/09/05 19:33:32 roberto Exp roberto $
** $Id: ldblib.c,v 1.21 2000/09/12 18:38:25 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -103,7 +103,7 @@ static int setlocal (lua_State *L) {
lua_Debug ar;
if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */
luaL_argerror(L, 1, "level out of range");
luaL_checktype(L, 3, "any");
luaL_checkany(L, 3);
lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2)));
return 1;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 1.41 2000/09/12 18:38:02 roberto Exp roberto $
** $Id: ldebug.c,v 1.42 2000/09/18 19:39:49 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@ -433,7 +433,7 @@ static const char *getfuncname (lua_State *L, StkId f, const char **name) {
void luaG_typeerror (lua_State *L, StkId o, const char *op) {
const char *name;
const char *kind = getobjname(L, o, &name);
const char *t = luaO_typename(o);
const char *t = luaO_typename(L, o);
if (kind)
luaO_verror(L, "attempt to %.30s %.20s `%.40s' (a %.10s value)",
op, kind, name, t);
@ -442,7 +442,7 @@ void luaG_typeerror (lua_State *L, StkId o, const char *op) {
}
void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op) {
void luaG_binerror (lua_State *L, StkId p1, lua_Tag t, const char *op) {
if (ttype(p1) == t) p1++;
LUA_ASSERT(ttype(p1) != t, "must be an error");
luaG_typeerror(L, p1, op);
@ -450,8 +450,8 @@ void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op) {
void luaG_ordererror (lua_State *L, StkId top) {
const char *t1 = luaO_typename(top-2);
const char *t2 = luaO_typename(top-1);
const char *t1 = luaO_typename(L, top-2);
const char *t2 = luaO_typename(L, top-1);
if (t1[2] == t2[2])
luaO_verror(L, "attempt to compare two %.10s values", t1);
else

View File

@ -1,5 +1,5 @@
/*
** $Id: ldebug.h,v 1.4 2000/08/10 19:50:47 roberto Exp roberto $
** $Id: ldebug.h,v 1.5 2000/08/11 16:17:28 roberto Exp roberto $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
*/
@ -13,7 +13,7 @@
void luaG_typeerror (lua_State *L, StkId o, const char *op);
void luaG_binerror (lua_State *L, StkId p1, lua_Type t, const char *op);
void luaG_binerror (lua_State *L, StkId p1, lua_Tag t, const char *op);
int luaG_getline (int *lineinfo, int pc, int refline, int *refi);
void luaG_ordererror (lua_State *L, StkId top);

4
ldo.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.98 2000/09/29 12:42:13 roberto Exp roberto $
** $Id: ldo.c,v 1.99 2000/10/02 14:47:43 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@ -332,7 +332,7 @@ struct lua_longjmp {
static void message (lua_State *L, const char *s) {
const TObject *em = luaH_getglobal(L, LUA_ERRORMESSAGE);
if (*luaO_typename(em) == 'f') {
if (luaO_type(em) == LUA_TFUNCTION) {
*L->top = *em;
incr_top;
lua_pushstring(L, s);

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.84 2000/09/14 14:09:31 roberto Exp roberto $
** $Id: liolib.c,v 1.85 2000/09/22 18:14:06 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -449,7 +449,7 @@ static int io_write (lua_State *L) {
if (f) arg++;
else f = getfilebyref(L, ctrl, OUTFILE); /* get _OUTPUT */
for (; arg <= lastarg; arg++) {
if (lua_type(L, arg)[2] == 'm') { /* nuMber? */ /* LUA_NUMBER */
if (lua_type(L, arg) == LUA_TNUMBER) { /* LUA_NUMBER */
/* optimization: could be done exactly as for strings */
status = status && fprintf(f, "%.16g", lua_tonumber(L, arg)) > 0;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 1.48 2000/09/12 13:47:39 roberto Exp roberto $
** $Id: lobject.c,v 1.49 2000/09/29 12:42:13 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -17,16 +17,14 @@
#include "lstate.h"
/*
** you can use the fact that the 3rd letter of each name is always different
** (e-m-r-b-n-l) to compare and switch these strings
*/
const char *const luaO_typenames[] = { /* ORDER LUA_T */
"userdata", "number", "string", "table", "function", "function", "nil",
"function", "function"
const lua_Type luaO_typearr[] = { /* ORDER LUA_T */
LUA_TUSERDATA, LUA_TNUMBER, LUA_TSTRING, LUA_TTABLE,
LUA_TFUNCTION, LUA_TFUNCTION, LUA_TNIL
};
const TObject luaO_nilobject = {TAG_NIL, {NULL}};

View File

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 1.76 2000/09/11 20:29:27 roberto Exp roberto $
** $Id: lobject.h,v 1.77 2000/09/29 12:42:13 roberto Exp roberto $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -48,7 +48,7 @@ typedef enum {
TAG_LMARK, /* mark for Lua closures */
TAG_CMARK /* mark for C closures */
} lua_Type;
} lua_Tag;
/* tags for values visible from Lua == first user-created tag */
#define NUM_TAGS 7
@ -80,7 +80,7 @@ typedef union {
typedef struct lua_TObject {
lua_Type ttype;
lua_Tag ttype;
Value value;
} TObject;
@ -189,10 +189,12 @@ typedef struct CallInfo {
} CallInfo;
extern const char *const luaO_typenames[];
extern const lua_Type luaO_typearr[];
extern const TObject luaO_nilobject;
#define luaO_typename(o) luaO_typenames[ttype(o)]
#define luaO_tag2type(t) (luaO_typearr[(int)(t)])
#define luaO_type(o) (luaO_tag2type(ttype(o)))
#define luaO_typename(L, o) (lua_typename(L, luaO_type(o)))
lint32 luaO_power2 (lint32 n);
char *luaO_openspace (lua_State *L, size_t n);

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 1.45 2000/09/29 12:42:13 roberto Exp roberto $
** $Id: ltests.c,v 1.46 2000/10/02 14:47:43 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -182,7 +182,7 @@ static int hash_query (lua_State *L) {
}
else {
Hash *t;
luaL_checktype(L, 2, "table");
luaL_checktype(L, 2, LUA_TTABLE);
t = hvalue(luaA_index(L, 2));
lua_pushnumber(L, luaH_mainposition(t, luaA_index(L, 1)) - t->node);
}
@ -193,7 +193,7 @@ static int hash_query (lua_State *L) {
static int table_query (lua_State *L) {
const Hash *t;
int i = luaL_opt_int(L, 2, -1);
luaL_checktype(L, 1, "table");
luaL_checktype(L, 1, LUA_TTABLE);
t = hvalue(luaA_index(L, 1));
if (i == -1) {
lua_pushnumber(L, t->size);
@ -238,7 +238,7 @@ static int string_query (lua_State *L) {
static int tref (lua_State *L) {
luaL_checktype(L, 1, "any");
luaL_checkany(L, 1);
lua_pushvalue(L, 1);
lua_pushnumber(L, lua_ref(L, luaL_opt_int(L, 2, 1)));
return 1;
@ -262,7 +262,7 @@ static int newuserdata (lua_State *L) {
}
static int udataval (lua_State *L) {
luaL_checktype(L, 1, "userdata");
luaL_checktype(L, 1, LUA_TUSERDATA);
lua_pushnumber(L, (int)lua_touserdata(L, 1));
return 1;
}
@ -290,7 +290,7 @@ static int loadlib (lua_State *L) {
}
static int closestate (lua_State *L) {
luaL_checktype(L, 1, "userdata");
luaL_checktype(L, 1, LUA_TUSERDATA);
lua_close((lua_State *)lua_touserdata(L, 1));
return 0;
}
@ -299,7 +299,7 @@ static int doremote (lua_State *L) {
lua_State *L1;
const char *code = luaL_check_string(L, 2);
int status;
luaL_checktype(L, 1, "userdata");
luaL_checktype(L, 1, LUA_TUSERDATA);
L1 = (lua_State *)lua_touserdata(L, 1);
status = lua_dostring(L1, code);
if (status != 0) {
@ -316,7 +316,7 @@ static int doremote (lua_State *L) {
}
static int settagmethod (lua_State *L) {
luaL_checktype(L, 3, "any");
luaL_checkany(L, 3);
lua_settagmethod(L, luaL_check_int(L, 1), luaL_check_string(L, 2));
return 1;
}
@ -436,7 +436,7 @@ static int testC (lua_State *L) {
lua_dostring(L, luaL_check_string(L, getnum));
}
else if EQ("type") {
lua_pushstring(L, lua_type(L, getnum));
lua_pushstring(L, lua_typename(L, lua_type(L, getnum)));
}
else luaL_verror(L, "unknown instruction %.30s", buff);
}

6
ltm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: ltm.c,v 1.49 2000/09/11 20:29:27 roberto Exp roberto $
** $Id: ltm.c,v 1.50 2000/09/29 12:42:13 roberto Exp roberto $
** Tag methods
** See Copyright Notice in lua.h
*/
@ -118,7 +118,7 @@ int lua_copytagmethods (lua_State *L, int tagto, int tagfrom) {
int luaT_effectivetag (lua_State *L, const TObject *o) {
lua_Type t = ttype(o);
lua_Tag t = ttype(o);
switch (t) {
case TAG_USERDATA: {
int tag = tsvalue(o)->u.d.tag;
@ -151,7 +151,7 @@ void lua_settagmethod (lua_State *L, int t, const char *event) {
checktag(L, t);
if (!luaT_validevent(t, e))
luaO_verror(L, "cannot change `%.20s' tag method for type `%.20s'%.20s",
luaT_eventname[e], luaO_typenames[t],
luaT_eventname[e], lua_typename(L, luaO_tag2type(t)),
(t == TAG_TABLE || t == TAG_USERDATA) ? " with default tag"
: "");
temp = *(L->top - 1);

24
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.70 2000/09/18 19:39:18 roberto Exp roberto $
** $Id: lua.h,v 1.71 2000/10/02 14:47:43 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
@ -48,6 +48,13 @@ typedef struct lua_State lua_State;
typedef int (*lua_CFunction) (lua_State *L);
typedef enum lua_Type {
LUA_NOVALUE, LUA_TUSERDATA, LUA_TNUMBER, LUA_TSTRING,
LUA_TTABLE, LUA_TFUNCTION, LUA_TNIL
} lua_Type;
/*
** state manipulation
*/
@ -70,8 +77,10 @@ int lua_stackspace (lua_State *L);
** access functions (stack -> C)
*/
const char *lua_type (lua_State *L, int index);
lua_Type lua_type (lua_State *L, int index);
const char *lua_typename (lua_State *L, lua_Type t);
int lua_isnumber (lua_State *L, int index);
int lua_isstring (lua_State *L, int index);
int lua_iscfunction (lua_State *L, int index);
int lua_tag (lua_State *L, int index);
@ -171,12 +180,11 @@ void lua_concat (lua_State *L, int n);
#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
#define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t))
#define lua_isfunction(L,n) (*lua_type(L,n) == 'f')
#define lua_isstring(L,n) (lua_tostring(L,n) != 0)
#define lua_istable(L,n) (*lua_type(L,n) == 't')
#define lua_isuserdata(L,n) (*lua_type(L,n) == 'u')
#define lua_isnil(L,n) (lua_type(L,n)[2] == 'l')
#define lua_isnull(L,n) (*lua_type(L,n) == 'N')
#define lua_isfunction(L,n) (lua_type(L,n) == LUA_TFUNCTION)
#define lua_istable(L,n) (lua_type(L,n) == LUA_TTABLE)
#define lua_isuserdata(L,n) (lua_type(L,n) == LUA_TUSERDATA)
#define lua_isnil(L,n) (lua_type(L,n) == LUA_TNIL)
#define lua_isnull(L,n) (lua_type(L,n) == LUA_NOVALUE)
#endif

4
lvm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 1.137 2000/09/25 14:48:42 roberto Exp roberto $
** $Id: lvm.c,v 1.138 2000/10/02 14:47:43 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -85,7 +85,7 @@ static void traceexec (lua_State *L, StkId base, StkId top, lua_Hook linehook) {
}
static Closure *luaV_closure (lua_State *L, lua_Type t, int nelems) {
static Closure *luaV_closure (lua_State *L, lua_Tag t, int nelems) {
Closure *c = luaF_newclosure(L, nelems);
L->top -= nelems;
while (nelems--)