lua-users home
lua-l archive

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

Anyone got any ideas how I can solve this? Believe me I have tried but there is very little information in the list archives of setting the environment that I can find. Or is this discussed in PiL book as i'll quite happily buy it if it explains what I need;)



Martin Slater wrote:

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 ?



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.
luabind-user mailing list

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.323 / Virus Database: 267.8.1/28 - Release Date: 24/06/2005