Added support for writing the file path of a script to the lua package.path to help with loading scripts within lua.
git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14451 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
@@ -28,6 +28,16 @@ class ReaderWriterLua : public osgDB::ReaderWriter
|
||||
|
||||
virtual const char* className() const { return "Lua ScriptEngine plugin"; }
|
||||
|
||||
lua::LuaScriptEngine* createScriptEngine(const osgDB::ReaderWriter::Options* options) const
|
||||
{
|
||||
osg::ref_ptr<lua::LuaScriptEngine> se = new lua::LuaScriptEngine();
|
||||
|
||||
// add file paths
|
||||
if (options) se->addPaths(options);
|
||||
else se->addPaths(osgDB::Registry::instance()->getOptions());
|
||||
|
||||
return se.release();
|
||||
}
|
||||
|
||||
|
||||
virtual ReadResult readObjectFromScript(std::istream& fin, const osgDB::ReaderWriter::Options* options =NULL) const
|
||||
@@ -42,7 +52,8 @@ class ReaderWriterLua : public osgDB::ReaderWriter
|
||||
osg::Parameters inputParameters;
|
||||
osg::Parameters outputParameters;
|
||||
|
||||
osg::ref_ptr<lua::LuaScriptEngine> se = new lua::LuaScriptEngine();
|
||||
osg::ref_ptr<lua::LuaScriptEngine> se = createScriptEngine(options);
|
||||
|
||||
if (!se->run(script.get(), entryPoint, inputParameters, outputParameters)) return 0;
|
||||
|
||||
if (outputParameters.empty()) return 0;
|
||||
@@ -85,7 +96,10 @@ class ReaderWriterLua : public osgDB::ReaderWriter
|
||||
|
||||
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options =NULL) const
|
||||
{
|
||||
if (file=="ScriptEngine.lua") return new lua::LuaScriptEngine();
|
||||
if (file=="ScriptEngine.lua")
|
||||
{
|
||||
return createScriptEngine(options);
|
||||
}
|
||||
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(file);
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
@@ -93,10 +107,13 @@ class ReaderWriterLua : public osgDB::ReaderWriter
|
||||
std::string fileName = osgDB::findDataFile( file, options );
|
||||
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
|
||||
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
|
||||
|
||||
osgDB::ifstream istream(fileName.c_str(), std::ios::in);
|
||||
if(!istream) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
return readObject(istream, options);
|
||||
return readObject(istream, local_opt.get());
|
||||
}
|
||||
|
||||
virtual ReadResult readImage(std::istream& fin, const osgDB::ReaderWriter::Options* options =NULL) const
|
||||
@@ -112,10 +129,13 @@ class ReaderWriterLua : public osgDB::ReaderWriter
|
||||
std::string fileName = osgDB::findDataFile( file, options );
|
||||
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
|
||||
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
|
||||
|
||||
osgDB::ifstream istream(fileName.c_str(), std::ios::in);
|
||||
if(!istream) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
return readImage(istream, options);
|
||||
return readImage(istream, local_opt.get());
|
||||
}
|
||||
|
||||
virtual ReadResult readNode(std::istream& fin, const osgDB::ReaderWriter::Options* options =NULL) const
|
||||
@@ -123,7 +143,7 @@ class ReaderWriterLua : public osgDB::ReaderWriter
|
||||
return readObjectFromScript(fin, options);
|
||||
}
|
||||
|
||||
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options =NULL) const
|
||||
virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options =NULL) const
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(file);
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
@@ -131,10 +151,13 @@ class ReaderWriterLua : public osgDB::ReaderWriter
|
||||
std::string fileName = osgDB::findDataFile( file, options );
|
||||
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
|
||||
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
|
||||
|
||||
osgDB::ifstream istream(fileName.c_str(), std::ios::in);
|
||||
if(!istream) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
return readNode(istream, options);
|
||||
return readNode(istream, local_opt.get());
|
||||
}
|
||||
|
||||
virtual ReadResult readScript(std::istream& fin,const osgDB::ReaderWriter::Options* options =NULL) const
|
||||
|
||||
Reference in New Issue
Block a user