From f6834f4393eaa1055c2bbde82ebb33cc58be8371 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 2 Oct 2000 17:10:55 -0300 Subject: new API function `lua_type' + new type lua_Type --- lapi.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index f2cd0b0d..48488d3a 100644 --- a/lapi.c +++ b/lapi.c @@ -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--; } -- cgit v1.2.3-55-g6feb