Index: trunk/src/lua/lua_function.cc
===================================================================
--- trunk/src/lua/lua_function.cc	(revision 182)
+++ trunk/src/lua/lua_function.cc	(revision 182)
@@ -0,0 +1,66 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include <nv/lua/lua_function.hh>
+
+#include <nv/lua/lua_raw.hh>
+
+using namespace nv;
+
+lua::function_base::function_base( lua_State* L, const path& a_path, bool global /*= true*/ ) : L(L)
+{
+	if ( !a_path.resolve( L, global ) )
+	{
+		lua_pop( L, 1 );
+		throw std::runtime_error("not a valid path - " + a_path.to_string() );
+	}
+
+	if ( !lua_isfunction( L, -1 ) ) 
+	{
+		lua_pop( L, 1 );
+		throw std::runtime_error("not a valid function - " + a_path.to_string() );
+	}
+	m_ref = luaL_ref( L, LUA_REGISTRYINDEX );
+}
+
+lua::function_base::function_base( const function_base& func ) : L(L)
+{
+	lua_rawgeti( L, LUA_REGISTRYINDEX, func.m_ref );
+	m_ref = luaL_ref( L, LUA_REGISTRYINDEX );
+}
+
+lua::function_base::~function_base()
+{
+	luaL_unref( L, LUA_REGISTRYINDEX, m_ref );
+}
+
+lua::function_base& lua::function_base::operator=(const function_base& func)
+{
+	if ( this != &func ) 
+	{
+		L = func.L;
+		lua_rawgeti( L, LUA_REGISTRYINDEX, func.m_ref );
+		m_ref = luaL_ref( L, LUA_REGISTRYINDEX );
+	}
+	return *this;
+}
+
+void lua::function_base::retrieve()
+{
+	lua_rawgeti( L, LUA_REGISTRYINDEX, m_ref );
+}
+
+void lua::function_base::call( int args, int results )
+{
+	int status = lua_pcall( L, args, results, 0 );
+	if ( status != 0 )
+	{
+		std::string error = lua_tostring( L, -1 );
+		lua_pop( L, 1 );
+		throw std::runtime_error(error.c_str());
+	}
+}
+
Index: trunk/src/lua/lua_values.cc
===================================================================
--- trunk/src/lua/lua_values.cc	(revision 182)
+++ trunk/src/lua/lua_values.cc	(revision 182)
@@ -0,0 +1,104 @@
+// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/lua/lua_values.hh"
+
+#include "nv/lua/lua_raw.hh"
+#include "nv/object.hh"
+
+void nv::lua::detail::push_value( lua_State *L, long n )
+{
+	lua_pushinteger( L, n );
+}
+
+void nv::lua::detail::push_value( lua_State *L, double d )
+{
+	lua_pushnumber( L, d );
+}
+
+void nv::lua::detail::push_value( lua_State *L, bool n )
+{
+	lua_pushboolean( L, n );
+}
+
+void nv::lua::detail::push_value( lua_State *L, const char* s )
+{
+	lua_pushstring( L, s );
+}
+
+void nv::lua::detail::push_value( lua_State *L, const std::string& s )
+{
+	lua_pushstring( L, s.c_str() );
+}
+
+void nv::lua::detail::push_value( lua_State *L, object* o )
+{
+	if ( o == nullptr )
+	{
+		lua_pushnil( L );
+	}
+	else
+	{
+		lua_rawgeti( L, LUA_REGISTRYINDEX, o->get_lua_index() );
+	}
+}
+
+void nv::lua::detail::push_value( lua_State *L, void* p )
+{
+	lua_pushlightuserdata( L, p );
+}
+
+void nv::lua::detail::push_value( lua_State *L, const passer& p )
+{
+	p.push(L);
+}
+
+void nv::lua::detail::pop_value( lua_State *L, long& n )
+{
+	n = lua_tointeger( L, -1 );
+	lua_pop( L, 1 );
+}
+
+void nv::lua::detail::pop_value( lua_State *L, double& d )
+{
+	d = lua_tonumber( L, -1 );
+	lua_pop( L, 1 );
+}
+
+void nv::lua::detail::pop_value( lua_State *L, bool& n )
+{
+	n = lua_toboolean( L, -1 ) != 0;
+	lua_pop( L, 1 );
+}
+
+void nv::lua::detail::pop_value( lua_State *L, std::string& s )
+{
+	s = lua_tostring( L, -1 ); 
+	lua_pop( L, 1 );
+}
+
+void nv::lua::detail::pop_value( lua_State *L, object*& o )
+{
+	o = nullptr;
+	if ( lua_istable( L , -1 ) )
+	{
+		lua_pushstring( L, "__ptr" );
+		lua_rawget( L, -1 );
+		if ( lua_isuserdata( L, -1 ) )
+		{
+			o = (object*)( lua_touserdata( L, -1 ) );
+		} 
+		lua_pop( L, 1 );
+	}
+	lua_pop( L, 1 );
+}
+
+void nv::lua::detail::pop_value( lua_State *L, void*& p )
+{
+	p = lua_touserdata( L, -1 );
+	lua_pop( L, 1 );
+}
+
