__type metamethod
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user