From 6d8f40d13a374b5ceb7e0f11752dab2d44313fcc Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 24 Sep 2013 15:17:42 +0000 Subject: [PATCH] Added support for passing parameters in and out of scripts. Implemented support for osg::ValueObject in LuaScriptEngine. --- examples/osgpresentation/osgpresentation.cpp | 55 +++- include/osg/ScriptEngine | 17 +- src/osg/ScriptEngine.cpp | 18 +- src/osgPlugins/V8/V8ScriptEngine.cpp | 7 +- src/osgPlugins/V8/V8ScriptEngine.h | 4 +- src/osgPlugins/lua/LuaScriptEngine.cpp | 294 ++++++++++++++++++- src/osgPlugins/lua/LuaScriptEngine.h | 15 +- src/osgPlugins/python/PythonScriptEngine.cpp | 6 +- src/osgPlugins/python/PythonScriptEngine.h | 4 +- src/osgUtil/CullVisitor.cpp | 1 - 10 files changed, 397 insertions(+), 24 deletions(-) diff --git a/examples/osgpresentation/osgpresentation.cpp b/examples/osgpresentation/osgpresentation.cpp index c45f6919d..c5475bafc 100644 --- a/examples/osgpresentation/osgpresentation.cpp +++ b/examples/osgpresentation/osgpresentation.cpp @@ -146,12 +146,13 @@ int main(int argc, char** argv) presentation->setProperty("scale",1.0); - +#if 0 osgPresentation::PrintSupportedProperties psp(std::cout); presentation->accept(psp); osgPresentation::PrintProperties pp(std::cout); presentation->accept(pp); +#endif osgPresentation::LoadAction load; presentation->accept( load ); @@ -223,8 +224,13 @@ int main(int argc, char** argv) #endif } #endif + + + presentation->setName("[this is a test]"); +#if 0 + if (pi.setProperty(presentation.get(), "Name", std::string("[this is new improved test]"))) { OSG_NOTICE<<"setProperty(presentation.get(), Name) succeeded."< event = new osgGA::GUIEventAdapter; if (pi.getSupportedProperties(event.get(), properties, true)) { @@ -418,10 +423,52 @@ int main(int argc, char** argv) { OSG_NOTICE<<"No supported properites found."< luaScriptEngine = osgDB::readFile("ScriptEngine.lua"); + if (luaScriptEngine.valid()) + { + presentation->getOrCreateUserDataContainer()->addUserObject(luaScriptEngine.get()); + std::string str; + while (arguments.read("--lua", str)) + { + osg::ref_ptr script = osgDB::readFile(str); + if (script.valid()) + { + presentation->addUpdateCallback(new osg::ScriptCallback(script.get(),"doStuff")); + } + } -// return viewer.run(); + if (arguments.read("--test", str)) + { + osg::ref_ptr script = osgDB::readFile(str); + if (script.valid()) + { + osg::ScriptEngine::Parameters inputParameters; + osg::ScriptEngine::Parameters outputParameters; + + inputParameters.push_back(new osg::StringValueObject("string","my very first string input")); + inputParameters.push_back(new osg::DoubleValueObject("double",1.234)); + inputParameters.push_back(new osg::MatrixfValueObject("matrix",osg::Matrixf())); + + osg::ref_ptr svo = new osg::MatrixdValueObject("return", osg::Matrixd()); + outputParameters.push_back(svo.get()); + + if (luaScriptEngine->run(script.get(), "test", inputParameters, outputParameters)) + { + OSG_NOTICE<<"Successfully ran script : return value = "<getValue()< _script; + osg::ref_ptr