__type metamethod

This commit is contained in:
Glenn Maynard
2006-10-05 02:43:36 +00:00
parent 9affdf4b1a
commit f5780905df
2 changed files with 11 additions and 2 deletions
+10 -2
View File
@@ -57,10 +57,18 @@ LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
narg, ar.name, extramsg);
}
LUALIB_API int luaL_pushtype (lua_State *L, int narg) {
if (!luaL_callmeta(L, narg, "__type"))
lua_pushstring (L, luaL_typename(L, narg));
return 1;
}
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, luaL_typename(L, narg));
const char *msg;
luaL_pushtype(L, narg);
msg = lua_pushfstring(L, "%s expected, got %s",
tname, lua_tostring(L, -1));
return luaL_argerror(L, narg, msg);
}
+1
View File
@@ -107,6 +107,7 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
LUALIB_API int (luaL_pushtype) (lua_State *L, int idx);
#define luaL_dofile(L, fn) \
(luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0))