diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-02 17:10:55 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2000-10-02 17:10:55 -0300 |
| commit | f6834f4393eaa1055c2bbde82ebb33cc58be8371 (patch) | |
| tree | 3583008ef181106d0fc7e130300f12adc70a5854 /lapi.c | |
| parent | 78bc8e553d4190fc3b90be5b621fc0f3507586ef (diff) | |
| download | lua-f6834f4393eaa1055c2bbde82ebb33cc58be8371.tar.gz lua-f6834f4393eaa1055c2bbde82ebb33cc58be8371.tar.bz2 lua-f6834f4393eaa1055c2bbde82ebb33cc58be8371.zip | |
new API function `lua_type' + new type lua_Type
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 21 |
1 files changed, 17 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 1.101 2000/09/29 12:42:13 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.102 2000/10/02 14:47:43 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -116,8 +116,16 @@ void lua_pushvalue (lua_State *L, int index) { | |||
| 116 | return ((test) ? (value) : (default)); } | 116 | return ((test) ? (value) : (default)); } |
| 117 | 117 | ||
| 118 | 118 | ||
| 119 | const char *lua_type (lua_State *L, int index) { | 119 | lua_Type lua_type (lua_State *L, int index) { |
| 120 | btest(L, index, luaO_typename(o), "NO VALUE"); | 120 | btest(L, index, luaO_type(o), LUA_NOVALUE); |
| 121 | } | ||
| 122 | |||
| 123 | const char *lua_typename (lua_State *L, lua_Type t) { | ||
| 124 | static const char *const names[] = { | ||
| 125 | "NO VALUE", "userdata", "number", "string", "table", "function", "nil" | ||
| 126 | }; | ||
| 127 | UNUSED(L); | ||
| 128 | return names[(int)t]; | ||
| 121 | } | 129 | } |
| 122 | 130 | ||
| 123 | int lua_iscfunction (lua_State *L, int index) { | 131 | int lua_iscfunction (lua_State *L, int index) { |
| @@ -128,6 +136,11 @@ int lua_isnumber (lua_State *L, int index) { | |||
| 128 | btest(L, index, (tonumber(Index(L, index)) == 0), 0); | 136 | btest(L, index, (tonumber(Index(L, index)) == 0), 0); |
| 129 | } | 137 | } |
| 130 | 138 | ||
| 139 | int lua_isstring (lua_State *L, int index) { | ||
| 140 | lua_Type t = lua_type(L, index); | ||
| 141 | return (t == LUA_TSTRING || t == LUA_TNUMBER); | ||
| 142 | } | ||
| 143 | |||
| 131 | int lua_tag (lua_State *L, int index) { | 144 | int lua_tag (lua_State *L, int index) { |
| 132 | btest(L, index, | 145 | btest(L, index, |
| 133 | ((ttype(o) == TAG_USERDATA) ? tsvalue(o)->u.d.tag : | 146 | ((ttype(o) == TAG_USERDATA) ? tsvalue(o)->u.d.tag : |
| @@ -411,7 +424,7 @@ void lua_settag (lua_State *L, int tag) { | |||
| 411 | break; | 424 | break; |
| 412 | default: | 425 | default: |
| 413 | luaO_verror(L, "cannot change the tag of a %.20s", | 426 | luaO_verror(L, "cannot change the tag of a %.20s", |
| 414 | luaO_typename(L->top-1)); | 427 | luaO_typename(L, L->top-1)); |
| 415 | } | 428 | } |
| 416 | L->top--; | 429 | L->top--; |
| 417 | } | 430 | } |
