#include #include #include #include #include #include #include #include #include #include #include struct test_struct { std::string f; int i; }; int main(int, char* []) { nv::logger log(nv::LOG_TRACE); log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE ); log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE ); NV_LOG( nv::LOG_NOTICE, "Logging started" ); // create new Lua state { nv::lua::state state( true ); nlua_register_glm( state.get_raw() ); // run the Lua script state.do_file( "init.lua" ); for (;;) { nv::lua::stack_guard guard( &state ); int stack = guard.get_level(); std::string input; std::cout << "LUA (" << stack << ") > "; std::getline( std::cin, input ); if (input == "quit") { break; } if (input.find("=", 0) == std::string::npos && input.find("if", 0) == std::string::npos && input.find("return", 0) == std::string::npos) { input = "return " + input; } std::cout << "> " << input << std::endl; int code = luaL_loadstring( state.get_raw(), input.c_str() ); if (code == 0) code = lua_pcall( state.get_raw(), 0, LUA_MULTRET, 0); if (code != 0) { std::string error = lua_tostring( state.get_raw(), -1 ); std::cout << "ERROR : " << error << std::endl; continue; } if (lua_gettop( state.get_raw() ) > stack) { for ( int i = stack+1; i <= lua_gettop( state.get_raw() ); ++i ) { std::cout << nlua_typecontent( state.get_raw(), i ) << std::endl; } } } } NV_LOG( nv::LOG_NOTICE, "Logging stopped" ); return 0; }