diff options
-rw-r--r-- | lauxlib.c | 6 | ||||
-rw-r--r-- | lauxlib.h | 5 | ||||
-rw-r--r-- | lbaselib.c | 7 | ||||
-rw-r--r-- | lcorolib.c | 2 | ||||
-rw-r--r-- | ldblib.c | 3 | ||||
-rw-r--r-- | lstrlib.c | 4 | ||||
-rw-r--r-- | manual/manual.of | 26 |
7 files changed, 41 insertions, 12 deletions
@@ -185,7 +185,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { | |||
185 | } | 185 | } |
186 | 186 | ||
187 | 187 | ||
188 | static int typeerror (lua_State *L, int arg, const char *tname) { | 188 | int luaL_typeerror (lua_State *L, int arg, const char *tname) { |
189 | const char *msg; | 189 | const char *msg; |
190 | const char *typearg; /* name for the type of the actual argument */ | 190 | const char *typearg; /* name for the type of the actual argument */ |
191 | if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING) | 191 | if (luaL_getmetafield(L, arg, "__name") == LUA_TSTRING) |
@@ -200,7 +200,7 @@ static int typeerror (lua_State *L, int arg, const char *tname) { | |||
200 | 200 | ||
201 | 201 | ||
202 | static void tag_error (lua_State *L, int arg, int tag) { | 202 | static void tag_error (lua_State *L, int arg, int tag) { |
203 | typeerror(L, arg, lua_typename(L, tag)); | 203 | luaL_typeerror(L, arg, lua_typename(L, tag)); |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
@@ -339,7 +339,7 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { | |||
339 | 339 | ||
340 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | 340 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { |
341 | void *p = luaL_testudata(L, ud, tname); | 341 | void *p = luaL_testudata(L, ud, tname); |
342 | if (p == NULL) typeerror(L, ud, tname); | 342 | luaL_argexpected(L, p != NULL, ud, tname); |
343 | return p; | 343 | return p; |
344 | } | 344 | } |
345 | 345 | ||
@@ -48,6 +48,7 @@ LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); | |||
48 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); | 48 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); |
49 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); | 49 | LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); |
50 | LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); | 50 | LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); |
51 | LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname); | ||
51 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, | 52 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, |
52 | size_t *l); | 53 | size_t *l); |
53 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, | 54 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, |
@@ -126,6 +127,10 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, | |||
126 | 127 | ||
127 | #define luaL_argcheck(L, cond,arg,extramsg) \ | 128 | #define luaL_argcheck(L, cond,arg,extramsg) \ |
128 | ((void)((cond) || luaL_argerror(L, (arg), (extramsg)))) | 129 | ((void)((cond) || luaL_argerror(L, (arg), (extramsg)))) |
130 | |||
131 | #define luaL_argexpected(L,cond,arg,tname) \ | ||
132 | ((void)((cond) || luaL_typeerror(L, (arg), (tname)))) | ||
133 | |||
129 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) | 134 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) |
130 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) | 135 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) |
131 | 136 | ||
@@ -125,8 +125,7 @@ static int luaB_getmetatable (lua_State *L) { | |||
125 | static int luaB_setmetatable (lua_State *L) { | 125 | static int luaB_setmetatable (lua_State *L) { |
126 | int t = lua_type(L, 2); | 126 | int t = lua_type(L, 2); |
127 | luaL_checktype(L, 1, LUA_TTABLE); | 127 | luaL_checktype(L, 1, LUA_TTABLE); |
128 | luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, | 128 | luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); |
129 | "nil or table expected"); | ||
130 | if (luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL) | 129 | if (luaL_getmetafield(L, 1, "__metatable") != LUA_TNIL) |
131 | return luaL_error(L, "cannot change a protected metatable"); | 130 | return luaL_error(L, "cannot change a protected metatable"); |
132 | lua_settop(L, 2); | 131 | lua_settop(L, 2); |
@@ -145,8 +144,8 @@ static int luaB_rawequal (lua_State *L) { | |||
145 | 144 | ||
146 | static int luaB_rawlen (lua_State *L) { | 145 | static int luaB_rawlen (lua_State *L) { |
147 | int t = lua_type(L, 1); | 146 | int t = lua_type(L, 1); |
148 | luaL_argcheck(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, | 147 | luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1, |
149 | "table or string expected"); | 148 | "table or string"); |
150 | lua_pushinteger(L, lua_rawlen(L, 1)); | 149 | lua_pushinteger(L, lua_rawlen(L, 1)); |
151 | return 1; | 150 | return 1; |
152 | } | 151 | } |
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | static lua_State *getco (lua_State *L) { | 21 | static lua_State *getco (lua_State *L) { |
22 | lua_State *co = lua_tothread(L, 1); | 22 | lua_State *co = lua_tothread(L, 1); |
23 | luaL_argcheck(L, co, 1, "thread expected"); | 23 | luaL_argexpected(L, co, 1, "thread"); |
24 | return co; | 24 | return co; |
25 | } | 25 | } |
26 | 26 | ||
@@ -55,8 +55,7 @@ static int db_getmetatable (lua_State *L) { | |||
55 | 55 | ||
56 | static int db_setmetatable (lua_State *L) { | 56 | static int db_setmetatable (lua_State *L) { |
57 | int t = lua_type(L, 2); | 57 | int t = lua_type(L, 2); |
58 | luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, | 58 | luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table"); |
59 | "nil or table expected"); | ||
60 | lua_settop(L, 2); | 59 | lua_settop(L, 2); |
61 | lua_setmetatable(L, 1); | 60 | lua_setmetatable(L, 1); |
62 | return 1; /* return 1st argument */ | 61 | return 1; /* return 1st argument */ |
@@ -857,9 +857,9 @@ static int str_gsub (lua_State *L) { | |||
857 | lua_Integer n = 0; /* replacement count */ | 857 | lua_Integer n = 0; /* replacement count */ |
858 | MatchState ms; | 858 | MatchState ms; |
859 | luaL_Buffer b; | 859 | luaL_Buffer b; |
860 | luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || | 860 | luaL_argexpected(L, tr == LUA_TNUMBER || tr == LUA_TSTRING || |
861 | tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, | 861 | tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3, |
862 | "string/function/table expected"); | 862 | "string/function/table"); |
863 | luaL_buffinit(L, &b); | 863 | luaL_buffinit(L, &b); |
864 | if (anchor) { | 864 | if (anchor) { |
865 | p++; lp--; /* skip anchor character */ | 865 | p++; lp--; /* skip anchor character */ |
diff --git a/manual/manual.of b/manual/manual.of index 8b5e5d93..0e8e3d72 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -4979,6 +4979,19 @@ This function never returns. | |||
4979 | 4979 | ||
4980 | } | 4980 | } |
4981 | 4981 | ||
4982 | @APIEntry{ | ||
4983 | void luaL_argexpected (lua_State *L, | ||
4984 | int cond, | ||
4985 | int arg, | ||
4986 | const char *tname);| | ||
4987 | @apii{0,0,v} | ||
4988 | |||
4989 | Checks whether @id{cond} is true. | ||
4990 | If it is not, raises an error about the type of the argument @id{arg} | ||
4991 | with a standard message @seeF{luaL_typeerror}. | ||
4992 | |||
4993 | } | ||
4994 | |||
4982 | @APIEntry{typedef struct luaL_Buffer luaL_Buffer;| | 4995 | @APIEntry{typedef struct luaL_Buffer luaL_Buffer;| |
4983 | 4996 | ||
4984 | Type for a @def{string buffer}. | 4997 | Type for a @def{string buffer}. |
@@ -5713,6 +5726,19 @@ to start the traceback. | |||
5713 | 5726 | ||
5714 | } | 5727 | } |
5715 | 5728 | ||
5729 | @APIEntry{const char *luaL_typeerror (lua_State *L, | ||
5730 | int arg, | ||
5731 | const char *tname);| | ||
5732 | @apii{0,0,v} | ||
5733 | |||
5734 | Raises a type error for argument @id{arg} | ||
5735 | of the @N{C function} that called it, | ||
5736 | using a standard message; | ||
5737 | @id{tname} is a @Q{name} for the expected type. | ||
5738 | This function never returns. | ||
5739 | |||
5740 | } | ||
5741 | |||
5716 | @APIEntry{const char *luaL_typename (lua_State *L, int index);| | 5742 | @APIEntry{const char *luaL_typename (lua_State *L, int index);| |
5717 | @apii{0,0,-} | 5743 | @apii{0,0,-} |
5718 | 5744 | ||