aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-02 17:10:55 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-02 17:10:55 -0300
commitf6834f4393eaa1055c2bbde82ebb33cc58be8371 (patch)
tree3583008ef181106d0fc7e130300f12adc70a5854 /lauxlib.c
parent78bc8e553d4190fc3b90be5b621fc0f3507586ef (diff)
downloadlua-f6834f4393eaa1055c2bbde82ebb33cc58be8371.tar.gz
lua-f6834f4393eaa1055c2bbde82ebb33cc58be8371.tar.bz2
lua-f6834f4393eaa1055c2bbde82ebb33cc58be8371.zip
new API function `lua_type' + new type lua_Type
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/lauxlib.c b/lauxlib.c
index d1fdb31d..d6398795 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.36 2000/09/12 13:48:22 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.37 2000/09/29 12:40:56 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -40,11 +40,11 @@ void luaL_argerror (lua_State *L, int narg, const char *extramsg) {
40} 40}
41 41
42 42
43static void type_error (lua_State *L, int narg, const char *type_name) { 43static void type_error (lua_State *L, int narg, lua_Type t) {
44 char buff[100]; 44 char buff[100];
45 const char *rt = lua_type(L, narg); 45 const char *rt = lua_typename(L, lua_type(L, narg));
46 if (*rt == 'N') rt = "no value"; 46 if (*rt == 'N') rt = "no value";
47 sprintf(buff, "%.10s expected, got %.10s", type_name, rt); 47 sprintf(buff, "%.10s expected, got %.10s", lua_typename(L, t), rt);
48 luaL_argerror(L, narg, buff); 48 luaL_argerror(L, narg, buff);
49} 49}
50 50
@@ -55,20 +55,21 @@ void luaL_checkstack (lua_State *L, int space, const char *mes) {
55} 55}
56 56
57 57
58/* 58void luaL_checktype(lua_State *L, int narg, lua_Type t) {
59** use the 3rd letter of type names for testing: 59 if (lua_type(L, narg) != t)
60** nuMber, niL, stRing, fuNction, usErdata, taBle, anY 60 type_error(L, narg, t);
61*/ 61}
62void luaL_checktype(lua_State *L, int narg, const char *tname) { 62
63 const char *rt = lua_type(L, narg); 63
64 if (!(*rt != 'N' && (tname[2] == 'y' || tname[2] == rt[2]))) 64void luaL_checkany (lua_State *L, int narg) {
65 type_error(L, narg, tname); 65 if (lua_type(L, narg) == LUA_NOVALUE)
66 luaL_argerror(L, narg, "value expected");
66} 67}
67 68
68 69
69const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { 70const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
70 const char *s = lua_tostring(L, narg); 71 const char *s = lua_tostring(L, narg);
71 if (!s) type_error(L, narg, "string"); 72 if (!s) type_error(L, narg, LUA_TSTRING);
72 if (len) *len = lua_strlen(L, narg); 73 if (len) *len = lua_strlen(L, narg);
73 return s; 74 return s;
74} 75}
@@ -88,7 +89,7 @@ const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
88double luaL_check_number (lua_State *L, int narg) { 89double luaL_check_number (lua_State *L, int narg) {
89 double d = lua_tonumber(L, narg); 90 double d = lua_tonumber(L, narg);
90 if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ 91 if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
91 type_error(L, narg, "number"); 92 type_error(L, narg, LUA_TNUMBER);
92 return d; 93 return d;
93} 94}
94 95