Index: trunk/tests/lualib_test/lualib_test.cc
===================================================================
--- trunk/tests/lualib_test/lualib_test.cc	(revision 73)
+++ trunk/tests/lualib_test/lualib_test.cc	(revision 74)
@@ -1,3 +1,4 @@
 #include <nv/lib/lua.hh>
+#include <nv/lua/lua_state.hh>
 #include <nv/lua/lua_raw.hh>
 #include <nv/lua/lua_glm.hh>
@@ -31,78 +32,57 @@
 	db.create_type<test_struct>().fields( fields );
 
-
 	nv::logger log(nv::LOG_TRACE);
 	log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
 	log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
-	nv::load_lua_library();
 	
 	NV_LOG( nv::LOG_NOTICE, "Logging started" );
 
 	// create new Lua state
-	lua_State *lua_state;
-	lua_state = luaL_newstate();
+	{
+		nv::lua::state state( true );
+		state.log_stack();
+		nlua_register_glm( state.get_raw() );
+		// run the Lua script
+		state.do_file( "init.lua" );
 
-	// load Lua libraries
-	static const luaL_Reg lualibs[] =
-	{
-		{ "base", luaopen_base },
-		{ NULL, NULL}
-	};
+		for (;;)
+		{
+			nv::lua::stack_guard guard( &state );
+			int stack = guard.get_level();
+			std::string input;
+			std::cout << "LUA (" << stack << ") > ";
+			std::getline( std::cin, input );
+			if (input == "quit")
+			{
+				break;
+			}
 
-	nlua_register_glm( lua_state );
+			if (input.find("=", 0) == std::string::npos && 
+				input.find("if", 0) == std::string::npos && 
+				input.find("return", 0) == std::string::npos)
+			{
+				input = "return " + input;
+			}
 
-	const luaL_Reg *lib = lualibs;
-	for(; lib->func != NULL; lib++)
-	{
-		lib->func(lua_state);
-		lua_settop(lua_state, 0);
-	}
+			std::cout << "> " << input << std::endl;
 
-	// run the Lua script
-	luaL_dofile(lua_state, "init.lua");
+			int code = luaL_loadstring( state.get_raw(), input.c_str() );
+			if (code == 0) code = lua_pcall( state.get_raw(), 0, LUA_MULTRET, 0);
+			if (code != 0)
+			{
+				std::string error = lua_tostring( state.get_raw(), -1 );
+				std::cout << "ERROR : " << error << std::endl;
+				continue;
+			}
 
-	for (;;)
-	{
-		std::string input;
-		int stack = lua_gettop( lua_state );
-		std::cout << "LUA (" << stack << ") > ";
-		std::getline( std::cin, input );
-		if (input == "quit")
-		{
-			break;
-		}
-
-		if (input.find("=", 0) == std::string::npos && 
-			input.find("if", 0) == std::string::npos && 
-			input.find("return", 0) == std::string::npos)
-		{
-			input = "return " + input;
-		}
-
-		std::cout << "> " << input << std::endl;
-
-		int code = luaL_loadstring( lua_state, input.c_str() );
-		if (code == 0) code = lua_pcall( lua_state, 0, LUA_MULTRET, 0);
-		if (code != 0)
-		{
-			std::string error = lua_tostring( lua_state, -1 );
-			std::cout << "ERROR : " << error << std::endl;
-			lua_settop( lua_state, stack );
-			continue;
-		}
-
-		if (lua_gettop( lua_state ) > stack)
-		{
-			for ( int i = stack+1; i <= lua_gettop( lua_state ); ++i )
+			if (lua_gettop( state.get_raw() ) > stack)
 			{
-				std::cout << nlua_typecontent( lua_state, i ) << std::endl;
+				for ( int i = stack+1; i <= lua_gettop( state.get_raw() ); ++i )
+				{
+					std::cout << nlua_typecontent( state.get_raw(), i ) << std::endl;
+				}
 			}
 		}
-		lua_settop( lua_state, stack );
 	}
-
-
-	// close the Lua state
-	lua_close(lua_state);
 	NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
 
