/************************************************************************ Test the libgfx scripting facility. by Michael Garland, 2000. $Id: t-script.cxx 426 2004-09-27 04:34:55Z garland $ ************************************************************************/ #include #include #include using namespace std; // usage: add * // Adds all numbers listed on the line and prints the result // // usage: avg * // Averages all numbers listed on the line and prints the result // int proc_add(const CmdLine &cmd) { std::vector values; double sum = 0.0; cmd.collect_as_numbers(values); std::vector::size_type count; for(count=0; count0 ) sum /= (double)count; cout << sum << endl; return SCRIPT_OK; } // usage: vec3 // Constructs a 3-vector and prints the result int proc_vec3(const CmdLine &cmd) { if( cmd.argcount() != 3 ) return SCRIPT_ERR_SYNTAX; Vec3 v; cmd.collect_as_numbers(v, 3); cout << v << endl; return SCRIPT_OK; } // usage: echo // Prints all the text following the command name verbatim int proc_echo(const CmdLine &cmd) { cout << cmd.argline() << endl; return SCRIPT_OK; } int main(int argc, char *argv[]) { CmdEnv env; env.register_command("add", proc_add); env.register_command("avg", proc_add); env.register_command("echo", proc_echo); env.register_command("vec3", proc_vec3); for(int i=1; i