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:
@@ -4343,3 +4343,40 @@ void LuaScriptEngine::assignClosure(const char* name, lua_CFunction fn) const
|
||||
lua_pushcclosure(_lua, fn, 1);
|
||||
lua_settable(_lua, -3);
|
||||
}
|
||||
|
||||
void LuaScriptEngine::addPaths(const osgDB::FilePathList& paths)
|
||||
{
|
||||
lua_getglobal( _lua, "package" );
|
||||
|
||||
lua_getfield( _lua, -1, "path" );
|
||||
std::string path = lua_tostring( _lua, -1 );
|
||||
lua_pop( _lua, 1 );
|
||||
|
||||
OSG_NOTICE<<"LuaScriptEngine::addPaths() original package.path = "<<path<<std::endl;
|
||||
|
||||
|
||||
for(osgDB::FilePathList::const_iterator itr = paths.begin();
|
||||
itr != paths.end();
|
||||
++itr)
|
||||
{
|
||||
OSG_NOTICE<<" Appending path ["<<*itr<<"]"<<std::endl;
|
||||
|
||||
path.append( ";" );
|
||||
path.append( *itr );
|
||||
path.append( "/?.lua" );
|
||||
}
|
||||
|
||||
OSG_NOTICE<<" path after = "<<path<<std::endl;
|
||||
|
||||
lua_pushstring( _lua, path.c_str() );
|
||||
lua_setfield( _lua, -2, "path" );
|
||||
|
||||
lua_pop( _lua, 1 ); // return stack to orignal
|
||||
}
|
||||
|
||||
void LuaScriptEngine::addPaths(const osgDB::Options* options)
|
||||
{
|
||||
if (!options) return;
|
||||
addPaths(options->getDatabasePathList());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user