From 2fef8c772b5d9c175941d4c8a64dedf736567466 Mon Sep 17 00:00:00 2001
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 11 Feb 2003 13:32:31 -0200
Subject: auxiliary function to check userdata with types

---
 lauxlib.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'lauxlib.c')

diff --git a/lauxlib.c b/lauxlib.c
index adc0f905..8fb01bc7 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.93 2003/01/27 13:46:16 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.94 2003/02/11 09:44:38 roberto Exp roberto $
 ** Auxiliary functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -121,6 +121,19 @@ LUALIB_API void luaL_checkany (lua_State *L, int narg) {
 }
 
 
+LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
+  if (!lua_getmetatable(L, ud)) return NULL;  /* no metatable? */
+  lua_pushstring(L, tname);
+  lua_rawget(L, LUA_REGISTRYINDEX);
+  if (!lua_rawequal(L, -1, -2)) {
+    lua_pop(L, 2);
+    return NULL;
+  }
+  lua_pop(L, 2);
+  return lua_touserdata(L, ud);
+}
+
+
 LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
   const char *s = lua_tostring(L, narg);
   if (!s) tag_error(L, narg, LUA_TSTRING);
-- 
cgit v1.2.3-55-g6feb