lua-users home
lua-l archive

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


Hi – I can’t seem to get Lua scripts to see the value of the LUA_CPATH environment variable if I set it within my Visual C++ application prior to calling the script.

 

As discussed in my previous post, I recently upgraded both my Visual Studio compiler (from 2010 to 2017) and my version of Lua (from 5.1 to 5.3.5).  One problem I’ve found after the upgrade is that it seems like the script does not recognise any changes I make to the LUA_CPATH environment variable within my application.  I first noticed this because I put a call require “iuplua” into the script, and it failed.  The error string showed no sign that it had looked where it should have looked, given the LUA_CPATH setting.  I tested what Lua thought the value of LUA_CPATH was by calling str = os.getenv("LUA_CPATH").  It set str to nil.  If I called os.getenv for “PATH” instead of “LUA_CPATH”, it returns the path as you’d expect (though that of course is set before my process is started, rather than being set within the process itself).

 

I set the value of the LUA_CPATH environment variable by calling _wputenv_s(L“LUA_CPATH”, sPath); within my application, before running the script.  I tried calling _wgetenv_s after setting it, just to confirm that the environment variable contained the path that I was expecting (it did).  I always set the environment variable before calling ::LoadLibrary to load lua53.dll and before calling any of its functions.  The only way I could get my require statement to work was by adding this line into the script before the require statement:

 

package.cpath = “c:\\Program Files (x86)\\My App\\?53.dll”

 

Before I upgraded my application, I previously ran Lua 5.1 using the same method for setting the LUA_CPATH environment variable.  If I call str = os.getenv("LUA_CPATH") in a script in that version of my application, it returns what I was expecting – the path I’d set it to.  So why is it nil now?  Is this a difference in behaviour between Visual Studio 2010 and 2017?  Can anyone suggest what’s going wrong?  All help much appreciated.

 

Simon