lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Hi there,


I'm using luabind in a data conversion utility that uses lua scripts to drive conversion, as resources are encountered that a file relies on it recursively converts these. The problem I am having it that i'm using lua global variables to pass information into the script but when it gets called again from within a script (c++ side) these obviously get overwritten so when the recursively called script is done the original has its globals set. I think I need to do something with lua_setfenv and LUA_GLOBALSINDEX but have got nowhere in resolving this problem as I'm pretty much a lua noob thanks to luabind and the simpicity of the scripts we use. The code I am using is at the end of the post.

Can anyone help me resolve this ?

thanks

Martin


std::string Driver::ProcessFile(const fs::path &inputPath, const fs::path &outDirectory, std::string scriptPath)
    {
// setup script global variables - just hides the manual lua calls to set them up
        luabind::object globals = luabind::get_globals(m_luaState);
        globals["InputPath"]  = inputPath.string();
        globals["InputFile"]  = inputPath.leaf();
        globals["OutputDir"]  = outDirectory.string();

        if(lua_dofile(m_luaState, scriptPath.c_str()) != 0) {
            // get the error string from the top of the stack
            const char *errStr = lua_tostring(m_luaState, 0);
            std::string error;

error = (boost::format("Failed executing - %s - %s") % scriptPath % (errStr ? errStr : "Unknown failure")).str();

            throw Core::Exception(error);
        }

        return m_outFilePath;
    }



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
luabind-user mailing list
luabind-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/luabind-user



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.7.10/25 - Release Date: 21/06/2005