summaryrefslogtreecommitdiff
path: root/src/libluaglue/LuaVM.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libluaglue/LuaVM.cpp')
-rw-r--r--src/libluaglue/LuaVM.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/libluaglue/LuaVM.cpp b/src/libluaglue/LuaVM.cpp
index d587897..7b165f1 100644
--- a/src/libluaglue/LuaVM.cpp
+++ b/src/libluaglue/LuaVM.cpp
@@ -3,6 +3,7 @@
#include <stdexcept>
#include <sstream>
#include <iostream>
+#include <string>
using namespace std;
@@ -50,9 +51,7 @@ void LuaVM::loadSource( const char *sourceFilename )
void LuaVM::executeMain( )
{
- int res;
-
- res = lua_pcall( m_lua, 0, LUA_MULTRET, 0 );
+ int res = lua_pcall( m_lua, 0, 0, 0 );
if( res != 0 ) {
ostringstream ss;
ss << "Can't execute main body of Lua source file '" << m_sourceFilename << "': " << lua_tostring( m_lua, -1 );
@@ -61,6 +60,22 @@ void LuaVM::executeMain( )
}
}
+void LuaVM::executeFunction( const string &f )
+{
+ //int top = lua_gettop( m_lua );
+ lua_getglobal( m_lua, f.c_str( ) );
+ int res = lua_pcall( m_lua, 0, LUA_MULTRET, 0 );
+ if( res != 0 ) {
+ ostringstream ss;
+ ss << "Unable to call Lua function '" << f << "': " << lua_tostring( m_lua, -1 );
+ lua_pop( m_lua, 1 );
+ throw new std::runtime_error( ss.str( ) );
+ }
+ //int nresults = lua_gettop( m_lua ) - top;
+
+ // TODO: return results
+}
+
void LuaVM::dumpState( )
{
lua_rawgeti( m_lua, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS );