name changes

This commit is contained in:
Roberto Ierusalimschy 2001-04-23 13:35:45 -03:00
parent beee01b170
commit 572a69b6af
7 changed files with 70 additions and 50 deletions

27
lapi.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.139 2001/04/11 18:39:37 roberto Exp roberto $
** $Id: lapi.c,v 1.140 2001/04/17 17:35:54 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@ -151,16 +151,16 @@ LUA_API int lua_type (lua_State *L, int index) {
}
LUA_API const l_char *lua_typename (lua_State *L, int t) {
LUA_API const l_char *lua_tag2name (lua_State *L, int tag) {
const l_char *s;
lua_lock(L);
s = (t == LUA_TNONE) ? l_s("no value") : basictypename(G(L), t);
s = (tag == LUA_TNONE) ? l_s("no value") : basictypename(G(L), tag);
lua_unlock(L);
return s;
}
LUA_API const l_char *lua_xtype (lua_State *L, int index) {
LUA_API const l_char *lua_xtypename (lua_State *L, int index) {
StkId o;
const l_char *type;
lua_lock(L);
@ -621,7 +621,7 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
** miscellaneous functions
*/
LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) {
LUA_API int lua_newxtype (lua_State *L, const l_char *name, int basictype) {
int tag;
lua_lock(L);
if (basictype != LUA_TNONE &&
@ -636,7 +636,7 @@ LUA_API int lua_newtype (lua_State *L, const l_char *name, int basictype) {
}
LUA_API int lua_type2tag (lua_State *L, const l_char *name) {
LUA_API int lua_name2tag (lua_State *L, const l_char *name) {
int tag;
const TObject *v;
lua_lock(L);
@ -798,3 +798,18 @@ LUA_API void lua_setweakmode (lua_State *L, int mode) {
lua_unlock(L);
}
/*
** deprecated function
*/
LUA_API void lua_pushusertag (lua_State *L, void *u, int tag) {
/* ???????? */
if (lua_pushuserdata(L, u) || 1) /* new udata? */
lua_settag(L, tag); /* OK, no conflit */
else {
if (lua_tag(L, -1) != tag) {
lua_error(L, "conflicting tags for the same userdata");
}
}
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.48 2001/02/23 17:17:25 roberto Exp roberto $
** $Id: lauxlib.c,v 1.49 2001/03/26 14:31:49 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@ -44,7 +44,7 @@ LUALIB_API void luaL_argerror (lua_State *L, int narg, const l_char *extramsg) {
static void type_error (lua_State *L, int narg, const l_char *tname) {
l_char buff[80];
sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_xtype(L, narg));
sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_xtypename(L,narg));
luaL_argerror(L, narg, buff);
}
@ -74,7 +74,7 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) {
LUALIB_API void *luaL_check_userdata (lua_State *L, int narg,
const l_char *name) {
if (strcmp(lua_xtype(L, narg), name) != 0)
if (strcmp(lua_xtypename(L, narg), name) != 0)
type_error(L, narg, name);
return lua_touserdata(L, narg);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.33 2001/04/11 14:42:41 roberto Exp roberto $
** $Id: lbaselib.c,v 1.34 2001/04/11 18:39:37 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -144,7 +144,7 @@ static int gettag (lua_State *L, int narg) {
return (int)lua_tonumber(L, narg);
case LUA_TSTRING: {
const l_char *name = lua_tostring(L, narg);
int tag = lua_type2tag(L, name);
int tag = lua_name2tag(L, name);
if (tag == LUA_TNONE)
luaL_verror(L, l_s("'%.30s' is not a valid type name"), name);
return tag;
@ -194,7 +194,7 @@ static int luaB_weakmode (lua_State *L) {
static int luaB_newtype (lua_State *L) {
const l_char *name = luaL_opt_string(L, 1, NULL);
lua_pushnumber(L, lua_newtype(L, name, LUA_TTABLE));
lua_pushnumber(L, lua_newxtype(L, name, LUA_TTABLE));
return 1;
}
@ -267,14 +267,14 @@ static int luaB_collectgarbage (lua_State *L) {
static int luaB_type (lua_State *L) {
luaL_checkany(L, 1);
lua_pushstring(L, lua_typename(L, lua_type(L, 1)));
lua_pushstring(L, lua_tag2name(L, lua_type(L, 1)));
return 1;
}
static int luaB_xtype (lua_State *L) {
luaL_checkany(L, 1);
lua_pushstring(L, lua_xtype(L, 1));
lua_pushstring(L, lua_xtypename(L, 1));
return 1;
}
@ -406,19 +406,19 @@ static int luaB_require (lua_State *L) {
}
static int aux_unwrap (lua_State *L, int arg) {
static int aux_unpack (lua_State *L, int arg) {
int n, i;
luaL_checktype(L, arg, LUA_TTABLE);
n = lua_getn(L, arg);
luaL_checkstack(L, n, l_s("table too big to unwrap"));
luaL_checkstack(L, n, l_s("table too big to unpack"));
for (i=1; i<=n; i++) /* push arg[1...n] */
lua_rawgeti(L, arg, i);
return n;
}
static int luaB_unwrap (lua_State *L) {
return aux_unwrap(L, 1);
static int luaB_unpack (lua_State *L) {
return aux_unpack(L, 1);
}
@ -437,7 +437,7 @@ static int luaB_call (lua_State *L) {
oldtop = lua_gettop(L); /* top before function-call preparation */
/* push function */
lua_pushvalue(L, 1);
n = aux_unwrap(L, 2); /* push arg[1...n] */
n = aux_unpack(L, 2); /* push arg[1...n] */
status = lua_call(L, n, LUA_MULTRET);
if (err != 0) { /* restore old error method */
lua_pushvalue(L, err);
@ -466,13 +466,13 @@ static int luaB_tostring (lua_State *L) {
lua_pushvalue(L, 1);
return 1;
case LUA_TTABLE:
sprintf(buff, l_s("%.40s: %p"), lua_xtype(L, 1), lua_topointer(L, 1));
sprintf(buff, l_s("%.40s: %p"), lua_xtypename(L, 1), lua_topointer(L, 1));
break;
case LUA_TFUNCTION:
sprintf(buff, l_s("function: %p"), lua_topointer(L, 1));
break;
case LUA_TUSERDATA: {
const l_char *t = lua_xtype(L, 1);
const l_char *t = lua_xtypename(L, 1);
if (strcmp(t, l_s("userdata")) == 0)
sprintf(buff, l_s("userdata(%d): %p"), lua_tag(L, 1),
lua_touserdata(L, 1));
@ -793,7 +793,7 @@ static const luaL_reg base_funcs[] = {
{l_s("sort"), luaB_sort},
{l_s("tinsert"), luaB_tinsert},
{l_s("tremove"), luaB_tremove},
{l_s("unwrap"), luaB_unwrap},
{l_s("unpack"), luaB_unpack},
{l_s("xtype"), luaB_xtype},
{l_s("weakmode"), luaB_weakmode}
};

18
lcode.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 1.66 2001/03/26 14:31:49 roberto Exp roberto $
** $Id: lcode.c,v 1.67 2001/04/06 18:25:00 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -265,14 +265,10 @@ void luaK_concat (FuncState *fs, int *l1, int l2) {
*l1 = l2;
else {
int list = *l1;
for (;;) { /* traverse `l1' */
int next = luaK_getjump(fs, list);
if (next == NO_JUMP) { /* end of list? */
luaK_fixjump(fs, list, l2);
return;
}
int next;
while ((next = luaK_getjump(fs, list)) != NO_JUMP) /* find last element */
list = next;
}
luaK_fixjump(fs, list, l2);
}
}
@ -310,8 +306,8 @@ void luaK_goiftrue (FuncState *fs, expdesc *v, int keepvalue) {
}
static void luaK_goiffalse (FuncState *fs, expdesc *v, int keepvalue) {
luaK_testgo(fs, v, 0, keepvalue ? OP_JMPONT : OP_JMPT);
static void luaK_goiffalse (FuncState *fs, expdesc *v) {
luaK_testgo(fs, v, 0, OP_JMPONT);
}
@ -385,7 +381,7 @@ void luaK_infix (LexState *ls, BinOpr op, expdesc *v) {
luaK_goiftrue(fs, v, 1);
break;
case OPR_OR:
luaK_goiffalse(fs, v, 1);
luaK_goiffalse(fs, v);
break;
default:
luaK_tostack(ls, v, 1); /* all other binary operators need a value */

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.110 2001/03/06 20:09:38 roberto Exp roberto $
** $Id: liolib.c,v 1.111 2001/03/26 14:31:49 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -75,14 +75,14 @@ static int pushresult (lua_State *L, int i) {
*/
#define checkfile(L,f) (strcmp(lua_xtype(L,(f)), FILEHANDLE) == 0)
#define checkfile(L,f) (strcmp(lua_xtypename(L,(f)), FILEHANDLE) == 0)
static FILE *getopthandle (lua_State *L, int inout) {
FILE *p = (FILE *)lua_touserdata(L, 1);
if (p != NULL) { /* is it a userdata ? */
if (!checkfile(L, 1)) {
if (strcmp(lua_xtype(L, 1), l_s("ClosedFileHandle")) == 0)
if (strcmp(lua_xtypename(L, 1), l_s("ClosedFileHandle")) == 0)
luaL_argerror(L, 1, l_s("file is closed"));
else
luaL_argerror(L, 1, l_s("(invalid value)"));
@ -102,7 +102,7 @@ static FILE *getopthandle (lua_State *L, int inout) {
static void pushfile (lua_State *L, FILE *f) {
lua_pushusertag(L, f, lua_type2tag(L, FILEHANDLE));
lua_pushusertag(L, f, lua_name2tag(L, FILEHANDLE));
}
@ -132,7 +132,7 @@ static int closefile (lua_State *L, FILE *f) {
return 1;
else {
lua_pushuserdata(L, f);
lua_settag(L, lua_type2tag(L, l_s("ClosedFileHandle")));
lua_settag(L, lua_name2tag(L, l_s("ClosedFileHandle")));
return (CLOSEFILE(L, f) == 0);
}
}
@ -678,8 +678,8 @@ static const luaL_reg iolib[] = {
LUALIB_API int lua_iolibopen (lua_State *L) {
int iotag = lua_newtype(L, FILEHANDLE, LUA_TUSERDATA);
lua_newtype(L, l_s("ClosedFileHandle"), LUA_TUSERDATA);
int iotag = lua_newxtype(L, FILEHANDLE, LUA_TUSERDATA);
lua_newxtype(L, l_s("ClosedFileHandle"), LUA_TUSERDATA);
luaL_openl(L, iolib);
/* predefined file handles */
setfile(L, stdin, INFILE);

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 1.78 2001/04/11 14:42:41 roberto Exp roberto $
** $Id: ltests.c,v 1.79 2001/04/17 17:35:54 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -433,8 +433,8 @@ static int udataval (lua_State *L) {
}
static int newtag (lua_State *L) {
lua_pushnumber(L, lua_newtype(L, lua_tostring(L, 1),
(int)lua_tonumber(L, 2)));
lua_pushnumber(L, lua_newxtype(L, lua_tostring(L, 1),
(int)lua_tonumber(L, 2)));
return 1;
}

23
lua.h
View File

@ -1,5 +1,5 @@
/*
** $Id: lua.h,v 1.95 2001/04/11 18:39:37 roberto Exp roberto $
** $Id: lua.h,v 1.96 2001/04/17 17:35:54 roberto Exp roberto $
** Lua - An Extensible Extension Language
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
** e-mail: info@lua.org
@ -124,8 +124,8 @@ LUA_API int lua_stackspace (lua_State *L);
*/
LUA_API int lua_type (lua_State *L, int index);
LUA_API const lua_char *lua_typename (lua_State *L, int t);
LUA_API const lua_char *lua_xtype (lua_State *L, int index);
LUA_API const lua_char *lua_tag2name (lua_State *L, int tag);
LUA_API const lua_char *lua_xtypename (lua_State *L, int index);
LUA_API int lua_isnumber (lua_State *L, int index);
LUA_API int lua_isstring (lua_State *L, int index);
LUA_API int lua_iscfunction (lua_State *L, int index);
@ -203,8 +203,8 @@ LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold);
/*
** miscellaneous functions
*/
LUA_API int lua_newtype (lua_State *L, const lua_char *name, int basictype);
LUA_API int lua_type2tag (lua_State *L, const lua_char *name);
LUA_API int lua_newxtype (lua_State *L, const lua_char *name, int basictype);
LUA_API int lua_name2tag (lua_State *L, const lua_char *name);
LUA_API int lua_copytagmethods (lua_State *L, int tagto, int tagfrom);
LUA_API void lua_settag (lua_State *L, int tag);
@ -223,6 +223,12 @@ LUA_API void lua_setweakmode (lua_State *L, int mode);
LUA_API int lua_getweakmode (lua_State *L, int index);
/*
** deprecated function
*/
LUA_API void lua_pushusertag (lua_State *L, void *u, int tag);
/*
** ===============================================================
** some useful macros
@ -234,7 +240,6 @@ LUA_API int lua_getweakmode (lua_State *L, int index);
#define lua_pop(L,n) lua_settop(L, -(n)-1)
#define lua_register(L,n,f) (lua_pushcfunction(L, f), lua_setglobal(L, n))
#define lua_pushusertag(L,u,t) (lua_pushuserdata(L, u), lua_settag(L, t))
#define lua_pushcfunction(L,f) lua_pushcclosure(L, f, 0)
#define lua_clonetag(L,t) lua_copytagmethods(L, lua_newtag(L), (t))
@ -249,7 +254,11 @@ LUA_API int lua_getweakmode (lua_State *L, int index);
#define lua_newtag(L) lua_newtype(L, NULL, LUA_TNONE)
/*
** compatibility macros
*/
#define lua_newtag(L) lua_newxtype(L, NULL, LUA_TNONE)
#define lua_typename lua_tag2name
#endif