Everything builds and works again.
[fail.git] / src / services / lua / test / testapp.cpp
blob879d99af836b48d07472c08025b48d339e61909b
1 #include <iostream>
3 #define lua_c
5 #include "lua/interface.h"
6 #include "lua/state.h"
7 #include "module_awful-luatest.h"
8 #include "testapp.h"
9 #include "lua/lua.h"
10 #include "lua/lauxlib.h"
11 #include "lua/lualib.h"
12 #include "lua/luaconf.h"
14 using namespace std;
15 using namespace luatestapp;
17 LuaTestApp::LuaTestApp() throw( std::runtime_error )
19 awful::LuaSetup< awful::luatest::awful_tag >();
21 luaL_openlibs( awful::LuaState::GetInstance()->get() );
24 LuaTestApp::~LuaTestApp()
28 void LuaTestApp::run()
30 //cout << "I see." << endl;
32 bool bQuit = false;
33 awful::LuaState* pState = awful::LuaState::GetInstance();
34 lua_State* pLS = pState->get();
36 while( !bQuit )
38 char buffer[512];
39 char* pCmdLine = buffer;
41 if( lua_readline( pLS, pCmdLine, "> " ) )
43 lua_pushstring( pLS, pCmdLine );
44 lua_saveline( pLS, -1 );
45 lua_remove( pLS, -1 );
47 if( !strcmp( pCmdLine, "q" ) )
48 bQuit = true;
49 else
51 if( !luaL_loadstring( pLS, pCmdLine ) )
53 switch( lua_pcall( pLS, 0, 0, 0 ) )
55 case LUA_ERRRUN:
57 const char* pErrMsg = lua_tostring( pLS, -1 );
58 std::cerr << pErrMsg << std::endl;
59 break;
62 case LUA_ERRMEM:
63 std::cerr << "LUA_ERRMEM" << std::endl;
64 break;
66 case LUA_ERRERR:
67 std::cerr << "LUA_ERRERR" << std::endl;
68 break;
71 else
72 cerr << "Syntax error" << endl;
75 lua_freeline( pState->get(), pCmdLine );
78 lua_settop( pState->get(), 0 );