LUA_CPATH environment variable value not detected in Lua script

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

LUA_CPATH environment variable value not detected in Lua script

Simon Orde-2

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)<a href="file:///\\My">\\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

 

Reply | Threaded
Open this post in threaded view
|

Re: LUA_CPATH environment variable value not detected in Lua script

Francisco Olarte
Simon:

On Wed, Mar 27, 2019 at 10:26 PM Simon Orde
<[hidden email]> wrote:
...> 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.

If os.getenv is working, it is in the environ. In the uses of lua we
have we alter package.cpath directly after creating the states ( as we
use multiple states with different setting in each ), and the manual
says..."Lua initializes the C path package.cpath in the same way it
initializes the Lua path package.path, using the environment variable
LUA_CPATH_5_3, ", but it is not clear to me if "Lua" here referes to
the library or the executable, so I went for the "use the source" and
found it int the luaopen_package. I think you may not be loading the
package library ( I do not know if require does it for you, or any
other thing, nor nearly enough data to check, and not familiar enough
with 5.1 to know if this has changed, but you should be ).

Francisco Olarte.

Reply | Threaded
Open this post in threaded view
|

Re: LUA_CPATH environment variable value not detected in Lua script

Antonio Scuri-2
  Hi,

  You could execute the Lua string:

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

  In C before loading the DLLs. 

Best,
Scuri


Em qui, 28 de mar de 2019 às 04:48, Francisco Olarte <[hidden email]> escreveu:
Simon:

On Wed, Mar 27, 2019 at 10:26 PM Simon Orde
<[hidden email]> wrote:
...> 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.

If os.getenv is working, it is in the environ. In the uses of lua we
have we alter package.cpath directly after creating the states ( as we
use multiple states with different setting in each ), and the manual
says..."Lua initializes the C path package.cpath in the same way it
initializes the Lua path package.path, using the environment variable
LUA_CPATH_5_3, ", but it is not clear to me if "Lua" here referes to
the library or the executable, so I went for the "use the source" and
found it int the luaopen_package. I think you may not be loading the
package library ( I do not know if require does it for you, or any
other thing, nor nearly enough data to check, and not familiar enough
with 5.1 to know if this has changed, but you should be ).

Francisco Olarte.

Reply | Threaded
Open this post in threaded view
|

RE: LUA_CPATH environment variable value not detected in Lua script

Simon Orde-2

OK thank you Scuri and Francisco.  I executed a string to set package.cpath and package.path and that worked.

 

Simon

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Antonio Scuri
Sent: 28 March 2019 1:39 PM
To: Lua mailing list
Subject: Re: LUA_CPATH environment variable value not detected in Lua script

 

  Hi,

 

  You could execute the Lua string:

 

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

 

  In C before loading the DLLs. 

 

Best,

Scuri

 

 

Em qui, 28 de mar de 2019 às 04:48, Francisco Olarte <[hidden email]> escreveu:

Simon:

On Wed, Mar 27, 2019 at 10:26 PM Simon Orde
<[hidden email]> wrote:
...> 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.

If os.getenv is working, it is in the environ. In the uses of lua we
have we alter package.cpath directly after creating the states ( as we
use multiple states with different setting in each ), and the manual
says..."Lua initializes the C path package.cpath in the same way it
initializes the Lua path package.path, using the environment variable
LUA_CPATH_5_3, ", but it is not clear to me if "Lua" here referes to
the library or the executable, so I went for the "use the source" and
found it int the luaopen_package. I think you may not be loading the
package library ( I do not know if require does it for you, or any
other thing, nor nearly enough data to check, and not familiar enough
with 5.1 to know if this has changed, but you should be ).

Francisco Olarte.