Added support for passing parameters in and out of scripts.

Implemented support for osg::ValueObject in LuaScriptEngine.
This commit is contained in:
Robert Osfield
2013-09-24 15:17:42 +00:00
parent 796314c339
commit 6d8f40d13a
10 changed files with 397 additions and 24 deletions

View File

@@ -40,7 +40,23 @@ void ScriptCallback::operator()(Node* node, NodeVisitor* nv)
ScriptEngine* engine = getScriptEngine(nv->getNodePath());
if (engine && _script.valid())
{
engine->run(_script.get());
// To handle the case where a NodeVisitor is created on the stack and can't be automatically ref counted
// we take a reference to prevent the inputParameters reference to the NodeVisitor making it's ref count going to zero and causing a delete.
ref_ptr<NodeVisitor> ref_nv(nv);
{
ScriptEngine::Parameters inputParameters;
inputParameters.push_back(node);
inputParameters.push_back(nv);
// empty outputParameters
ScriptEngine::Parameters outputParameters;
engine->run(_script.get(), _entryPoint, inputParameters, outputParameters);
}
// now release the ref_ptr used to protected the NodeVisitor from deletion.
ref_nv.release();
}
// note, callback is responsible for scenegraph traversal so