Index: trunk/src/engine/program_manager.cc
===================================================================
--- trunk/src/engine/program_manager.cc	(revision 433)
+++ trunk/src/engine/program_manager.cc	(revision 438)
@@ -9,10 +9,9 @@
 #include "nv/core/logging.hh"
 #include "nv/lua/lua_nova.hh"
-
+#include "nv/io/c_file_system.hh"
 
 nv::program_manager::program_manager( context* a_context ) : m_context( a_context )
 {
-	m_vertex_head   = a_context->get_device()->get_shader_header();
-	m_fragment_head = a_context->get_device()->get_shader_header();
+	m_shader_head = a_context->get_device()->get_shader_header();
 }
 
@@ -20,22 +19,22 @@
 {
 	NV_LOG_DEBUG( table.get_string("id") );
-	std::string vsource;
-	std::string fsource;
-	std::string csource;
+	string_buffer vsource;
+	string_buffer fsource;
+	string_buffer header( m_shader_head );
 	if ( table.is_table("common") )
 	{
 		lua::table_guard common( table, "common" );
-		load_source( common, csource, "" );
+		header.append( "\n" + load_source( common, "" ) + "\n" );
 	}
 	{
 		lua::table_guard vtable( table, "vertex" );
-		load_source( vtable, vsource, m_vertex_head+"\n"+csource+"\n");
+		vsource = load_source( vtable, header );
 	}
 	{
 		lua::table_guard ftable( table, "fragment" );
-		load_source( ftable, fsource, m_fragment_head+"\n"+csource+"\n" );
+		fsource = load_source( ftable, header );
 	}
 
-	nv::program program = m_context->get_device()->create_program( string_view( vsource.c_str(), vsource.size() ), string_view( fsource.c_str(), fsource.size() ) );
+	nv::program program = m_context->get_device()->create_program( vsource, fsource );
 	return add( program );
 }
@@ -46,10 +45,11 @@
 }
 
-void nv::program_manager::load_source( lua::table_guard& table, std::string& out, const std::string& append )
+nv::string_buffer nv::program_manager::load_source( lua::table_guard& table, const string_view& append )
 {
-	out = append;
+	c_file_system fs;
+	string_buffer out( append );
 	if ( table.is_string( "files" ) )
 	{
-		out += nv::slurp( table.get_std_string( "files" ) );
+		out.append( fs.slurp( table.get_string( "files" ) ) );
 	}
 	else if ( table.is_table( "files" ) )
@@ -59,7 +59,7 @@
 		for ( uint32 i = 1; i <= count; ++i )
 		{
-			std::string include( inctable.get<std::string,uint32>(i) );
-			if ( i == count ) out += "#line 1\n";
-			out += nv::slurp( include );
+			const_string include( inctable.get<const_string,uint32>(i) );
+			if ( i == count ) out.append( "#line 1\n" );
+			out.append( fs.slurp( include ) );
 		}
 	}
@@ -67,10 +67,12 @@
 	if ( table.is_string( "file" ) )
 	{
-		out += "#line 1\n" + nv::slurp( table.get_std_string( "file" ) );
+		const_string data = fs.slurp( table.get_string( "file" ) );
+		out.append( "#line 1\n" + data );
 	}
 
 	if ( table.is_string( "source" ) )
 	{
-		out += table.get_std_string( "source" );
+		out.append( table.get_string( "source" ) );
 	}
+	return out;
 }
