/* Copyright Robert Osfield, Licensed under the GPL * * Experimental base for refactor of Present3D * */ #include #include #include #include #include #include // hacky experiment with create lua, v8 and python to run scripts. #ifdef USE_LUA extern "C" { #include #include #include } void runLua(const std::string& str) { OSG_NOTICE< void runPython(const std::string& str) { OSG_NOTICE< void runV8(const std::string& str) { OSG_NOTICE< global = v8::ObjectTemplate::New(); v8::Persistent globalContext = v8::Context::New(NULL, global); v8::Persistent globalTemplate = v8::Persistent::New(global); std::string filePath = str; if(osgDB::fileExists(filePath)) { std::string js_source; std::ifstream fin(filePath.c_str()); if (fin) { // read file in the crude way. while(fin) { int c = fin.get(); if (c>=0 && c<=255) { js_source.push_back(c); } } // Create a nested handle scope v8::HandleScope local_handle_scope; // Enter the global context v8::Context::Scope context_scope(globalContext); // Create a string containing the JavaScript source code. v8::Handle source = v8::String::New(js_source.c_str()); // Compile the source code. v8::Handle script = v8::Script::Compile(source); // Run the script to get the result. v8::Handle result = script->Run(); // Convert the result to an ASCII string and print it. v8::String::AsciiValue ascii(result); printf("%s\n", *ascii); } } globalTemplate.Dispose(); globalContext.Dispose(); } isolate->Dispose(); } #endif int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); osgViewer::Viewer viewer(arguments); std::string str; #ifdef USE_LUA while (arguments.read("--lua",str)) { runLua(str); } #endif #ifdef USE_V8 while (arguments.read("--js",str)) { runV8(str); } #endif #ifdef USE_PYTHON while (arguments.read("--python",str)) { runPython(str); } #endif // create the model osg::ref_ptr model = osgDB::readNodeFiles(arguments); if (!model) return 1; viewer.setSceneData( model.get() ); return viewer.run(); }