diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-28 21:29:03 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-09-28 21:29:03 +0200 |
commit | b80687f17644766eb890598297c0f37bb898d76d (patch) | |
tree | 44e6a15cc058087a19dd44d44c2d1d52194a5876 /src/libluaglue | |
parent | c82a15eb0ffe61c1d2d2630981777f72013e833a (diff) | |
download | crawler-b80687f17644766eb890598297c0f37bb898d76d.tar.gz crawler-b80687f17644766eb890598297c0f37bb898d76d.tar.bz2 |
first Lua config of crawler
Diffstat (limited to 'src/libluaglue')
-rw-r--r-- | src/libluaglue/LuaVM.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/libluaglue/LuaVM.cpp b/src/libluaglue/LuaVM.cpp index f268823..9363cac 100644 --- a/src/libluaglue/LuaVM.cpp +++ b/src/libluaglue/LuaVM.cpp @@ -1,6 +1,11 @@ #include "LuaVM.hpp" -LuaVM::LuaVM( ) +#include <stdexcept> +#include <sstream> + +using namespace std; + +LuaVM::LuaVM( ) : m_lua( 0 ) { initialize( ); } @@ -13,4 +18,19 @@ LuaVM::~LuaVM( ) 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( ) ); + } } |