summaryrefslogtreecommitdiff
path: root/src/libluaglue/LuaVM.cpp
blob: 9363cacf81a1788c031dea7ce7248c94a7895cf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "LuaVM.hpp"

#include <stdexcept>
#include <sstream>

using namespace std;

LuaVM::LuaVM( ) : m_lua( 0 )
{
	initialize( );
}

LuaVM::~LuaVM( )
{
	lua_close( m_lua );
}

void LuaVM::initialize( )
{
	m_lua = luaL_newstate( );
	
	luaL_openlibs( m_lua );
}

void LuaVM::loadSource( const char *filename )
{
	int res;
	
	res = luaL_loadfile( m_lua, filename );
	if( res != 0 ) {
		ostringstream ss;
		ss << "Can't read Lua source file from file '" << filename << "': " << lua_tostring( m_lua, -1 );
		lua_pop( m_lua, 1 );
		throw std::runtime_error( ss.str( ) );
	}
}