[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Setting the lua environment
- From: "Richard Ranft" <rranft@...>
- Date: Sun, 26 Jun 2005 08:14:56 -0700
Is there some way to accomodate this from your script manager on the C++
side? If you use an object for each instance of the script in your manager
you could keep what info you needed with each script object, and pass on
what the next object will need to it when it is instantiated. I think this
would work and it would avoid stomping on the global environment.
Just a thought... I don't have many of them.
Rich
//-------------------Original Post-------------------------
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;)
thanks
Martin
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 ?
>
> 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.8.1/28 - Release Date: 24/06/2005