00001 #include <cppscript>
00002
00003 void clear_history(var history) { history["list"].clear(); }
00004 enable_pickle(clear_history);
00005
00006 void add_history(var history, var line) { history["list"].push_back(line); }
00007 enable_pickle(add_history);
00008
00009 void print_history(var history)
00010 {
00011 if(history["list"])
00012 foreach( line, history["list"] ) writeln(line);
00013 else
00014 writeln("(history is empty)");
00015 }
00016 enable_pickle(print_history);
00017
00018 var command_history()
00019 {
00020 return object("command_history").extend
00021 ("clear", clear_history)
00022 ("add", add_history)
00023 ("print", print_history)
00024 ("list", array());
00025 }
00026
00027 var script_main(var lines)
00028 {
00029 var history;
00030
00031 try
00032 {
00033 history=unpickle_file("history.dat");
00034 }
00035 catch(var)
00036 {
00037 history = command_history();
00038 }
00039
00040 if(lines[0] == "clear")
00041 history["clear"]();
00042 else
00043 foreach(line, lines) history["add"](line);
00044
00045 history["print"]();
00046 pickle_file("history.dat", history);
00047 return 0;
00048 }