Add readline support to eval.

This commit is contained in:
Jonathan Turner 2009-09-07 20:52:31 +00:00
parent 798908f127
commit 48e96b2f3b
2 changed files with 53 additions and 12 deletions

View File

@ -2,22 +2,42 @@ cmake_minimum_required(VERSION 2.6)
project(chaiscript)
SET (CMAKE_BUILD_TYPE gdb)
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
FIND_LIBRARY(READLINE_LIBRARY NAMES readline PATH /usr/lib /usr/local/lib /opt/local/lib)
#SET (CMAKE_BUILD_TYPE rel)
#SET (CMAKE_C_FLAGS_REL " -Wall -O3")
#SET (CMAKE_CXX_FLAGS_REL " -Wall -O3")
MESSAGE(STATUS "Detecting readline support")
if (READLINE_LIBRARY)
MESSAGE(STATUS "Found: ${READLINE_LIBRARY}")
SET (READLINE_LIB readline)
SET (CMAKE_BUILD_TYPE gdb)
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb -DREADLINE_AVAILABLE")
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb -DREADLINE_AVAILABLE")
#SET (CMAKE_BUILD_TYPE rel)
#SET (CMAKE_C_FLAGS_REL " -Wall -O3 -DREADLINE_AVAILABLE")
#SET (CMAKE_CXX_FLAGS_REL " -Wall -O3 -DREADLINE_AVAILABLE")
else(READLINE_LIBRARY)
MESSAGE(STATUS "Not Found")
SET (READLINE_LIB )
SET (CMAKE_BUILD_TYPE gdb)
SET (CMAKE_C_FLAGS_GDB " -Wall -ggdb")
SET (CMAKE_CXX_FLAGS_GDB " -Wall -ggdb")
#SET (CMAKE_BUILD_TYPE rel)
#SET (CMAKE_C_FLAGS_REL " -Wall -O3")
#SET (CMAKE_CXX_FLAGS_REL " -Wall -O3")
endif(READLINE_LIBRARY)
include_directories(include)
find_package(Boost 1.36.0 COMPONENTS thread)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(chaiscript_eval src/main.cpp)
#add_executable(dispatchkit_test contrib/test/dispatchkit_test.cpp)
target_link_libraries(chaiscript_eval dl ${Boost_LIBRARIES})
target_link_libraries(chaiscript_eval dl ${Boost_LIBRARIES} ${READLINE_LIB})
add_library(test MODULE src/test_module.cpp)
target_link_libraries(test ${Boost_LIBRARIES})

View File

@ -8,6 +8,11 @@
#include <list>
#ifdef READLINE_AVAILABLE
#include <readline/readline.h>
#include <readline/history.h>
#endif
#include <chaiscript/chaiscript.hpp>
void print_help() {
@ -17,16 +22,33 @@ void print_help() {
std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl;
}
std::string get_next_command() {
#ifdef READLINE_AVAILABLE
char *input_raw;
input_raw = readline("eval> ");
add_history(input_raw);
return std::string(input_raw);
#else
std::string retval;
std::cout << "eval> ";
std::getline(std::cin, retval);
return retval;
#endif
}
int main(int argc, char *argv[]) {
std::string input;
chaiscript::ChaiScript chai;
chai.add(chaiscript::bootstrap::list_type<std::list<chaiscript::Boxed_Value> >("List"));
if (argc < 2) {
std::cout << "eval> ";
std::getline(std::cin, input);
//std::cout << "eval> ";
//std::getline(std::cin, input);
#ifdef READLINE_AVAILABLE
using_history();
#endif
input = get_next_command();
while (input != "quit") {
chaiscript::Boxed_Value val;
@ -54,8 +76,7 @@ int main(int argc, char *argv[]) {
}
}
std::cout << "eval> ";
std::getline(std::cin, input);
input = get_next_command();
}
}
else {