diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-30 16:27:03 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-12-30 16:27:03 -0200 |
commit | 607012ece156112f9c45620ce130699f5448db63 (patch) | |
tree | 868aa77f305eda56beca73d75c56ba6304b8b356 /lbuiltin.c | |
parent | 0652906e7a6be897d67c5246c7897d1d10b683ff (diff) | |
download | lua-607012ece156112f9c45620ce130699f5448db63.tar.gz lua-607012ece156112f9c45620ce130699f5448db63.tar.bz2 lua-607012ece156112f9c45620ce130699f5448db63.zip |
tag method must be a function
+ error message must be a string
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.89 1999/12/27 17:33:22 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.90 1999/12/28 19:23:41 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -106,8 +106,9 @@ void luaB__ALERT (lua_State *L) { | |||
106 | void luaB__ERRORMESSAGE (lua_State *L) { | 106 | void luaB__ERRORMESSAGE (lua_State *L) { |
107 | lua_Object al = lua_rawgetglobal(L, "_ALERT"); | 107 | lua_Object al = lua_rawgetglobal(L, "_ALERT"); |
108 | if (lua_isfunction(L, al)) { /* avoid error loop if _ALERT is not defined */ | 108 | if (lua_isfunction(L, al)) { /* avoid error loop if _ALERT is not defined */ |
109 | char buff[600]; | 109 | const char *s = luaL_check_string(L, 1); |
110 | sprintf(buff, "error: %.500s\n", luaL_check_string(L, 1)); | 110 | char *buff = luaL_openspace(L, strlen(s)+sizeof("error: \n")); |
111 | strcpy(buff, "error: "); strcat(buff, s); strcat(buff, "\n"); | ||
111 | lua_pushstring(L, buff); | 112 | lua_pushstring(L, buff); |
112 | lua_callfunction(L, al); | 113 | lua_callfunction(L, al); |
113 | } | 114 | } |
@@ -169,7 +170,7 @@ void luaB_tonumber (lua_State *L) { | |||
169 | 170 | ||
170 | 171 | ||
171 | void luaB_error (lua_State *L) { | 172 | void luaB_error (lua_State *L) { |
172 | lua_error(L, lua_getstring(L, lua_getparam(L, 1))); | 173 | lua_error(L, luaL_opt_string(L, 1, NULL)); |
173 | } | 174 | } |
174 | 175 | ||
175 | void luaB_setglobal (lua_State *L) { | 176 | void luaB_setglobal (lua_State *L) { |
@@ -231,6 +232,8 @@ void luaB_settagmethod (lua_State *L) { | |||
231 | int tag = luaL_check_int(L, 1); | 232 | int tag = luaL_check_int(L, 1); |
232 | const char *event = luaL_check_string(L, 2); | 233 | const char *event = luaL_check_string(L, 2); |
233 | lua_Object nf = luaL_nonnullarg(L, 3); | 234 | lua_Object nf = luaL_nonnullarg(L, 3); |
235 | luaL_arg_check(L, lua_isnil(L, nf) || lua_isfunction(L, nf), 3, | ||
236 | "function or nil expected"); | ||
234 | #ifndef LUA_COMPAT_GC | 237 | #ifndef LUA_COMPAT_GC |
235 | if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL) | 238 | if (strcmp(event, "gc") == 0 && tag != LUA_T_NIL) |
236 | lua_error(L, "cannot set this tag method from Lua"); | 239 | lua_error(L, "cannot set this tag method from Lua"); |