Index: trunk/src/lua/lua_raw.cc
===================================================================
--- trunk/src/lua/lua_raw.cc	(revision 449)
+++ trunk/src/lua/lua_raw.cc	(revision 490)
@@ -38,6 +38,6 @@
 void nlua_pushreversed( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
-	int len = static_cast<int>( lua_rawlen( L, index ) );
+	index = nlua_absindex( L, index );
+	int len = static_cast<int>( nlua_rawlen( L, index ) );
 	int i   = len;
 	lua_createtable( L, len, 0 );
@@ -53,5 +53,5 @@
 void nlua_shallowcopy( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	lua_createtable( L, 0, 0 );
 	lua_pushnil( L );
@@ -67,5 +67,5 @@
 void nlua_shallowicopy( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	lua_createtable( L, 0, 0 );
 	int i = 0;
@@ -85,5 +85,5 @@
 void nlua_shallowmerge( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	lua_pushnil( L );
 
@@ -98,5 +98,5 @@
 void nlua_deepcopy( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	lua_createtable( L, 0, 0 );
 	lua_pushnil( L );
@@ -118,5 +118,5 @@
 void nlua_toset( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	lua_createtable( L, 0, 0 );
 	int i = 0;
@@ -137,5 +137,5 @@
 void nlua_tokeyset( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	lua_createtable( L, 0, 0 );
 	lua_pushnil( L );
@@ -151,5 +151,5 @@
 void nlua_register( lua_State *L, const char* fname, lua_CFunction func, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	lua_pushstring( L, fname );
 	lua_pushcfunction( L, func );
@@ -159,5 +159,5 @@
 void nlua_register( lua_State *L, const luaL_Reg *l, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	for (; l->name != NULL; l++) 
 	{
@@ -200,5 +200,5 @@
 void nlua_toflags( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	nv::uint32 flag;
 	if ( lua_istable( L, index ) )
@@ -222,5 +222,5 @@
 void nlua_toflags_set( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	nv::uint32 flag;
 	if ( lua_istable( L, index ) )
@@ -241,5 +241,5 @@
 void nlua_toflags_array( lua_State *L, int index, nv::uint8* data, nv::uint32 count )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	nv::uint32 flag;
 	if ( lua_istable( L, index ) )
@@ -260,5 +260,5 @@
 nv::vector<nv::uint8> nlua_tobytearray( lua_State *L, int index )
 {
-	index = lua_absindex( L, index );
+	index = nlua_absindex( L, index );
 	nv::vector<nv::uint8> result;
 	if ( lua_istable( L, index ) )
@@ -273,2 +273,52 @@
 	return result;
 }
+
+void * nlua_testudata( lua_State *L, int ud, const char *tname )
+{
+	void *p = lua_touserdata( L, ud );
+	if ( p != NULL )
+	{
+		if ( lua_getmetatable( L, ud ) )
+		{
+			luaL_getmetatable( L, tname );
+			if ( !lua_rawequal( L, -1, -2 ) )
+				p = NULL;
+			lua_pop( L, 2 );
+			return p;
+		}
+	}
+	return NULL;
+}
+
+void nlua_setmetatable( lua_State *L, const char *tname )
+{
+	int only_works_for_51;
+	luaL_getmetatable( L, tname );
+	lua_setmetatable( L, -2 );
+}
+
+void nlua_requiref( lua_State *L, const char *modname, lua_CFunction openf, int glb )
+{
+	int only_works_for_51;
+	lua_pushcfunction( L, openf );
+	lua_pushstring( L, modname );
+	lua_call( L, 1, 1 );
+	if ( glb != 0 )
+	{
+		lua_pushvalue( L, LUA_GLOBALSINDEX );
+		lua_pushvalue( L, -2 );
+		lua_setfield( L, -2, modname );
+		lua_pop( L, 1 );
+	}
+}
+
+int nlua_rawlen( lua_State* L, int index )
+{
+	return lua_objlen( L, index );
+}
+
+void nlua_pushglobaltable( lua_State* L )
+{
+	int only_works_for_51;
+	lua_pushvalue( L, LUA_GLOBALSINDEX );
+}
