Environment variables

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

Environment variables

Szabolcs Szasz
Hello,

I need to support a simple config file written 
consisting purely of

    variable = "value"

pairs (actually a LUA file), and I need to ensure 
that those settings also get to environment vars
(before execing off to a custom executable from 
the host binary).

I thought of using a tagmethod for setglobal, but
that did not seem to be allowed. Also, the globals 
table is of not much help now (I guess).

What can I do? (I would definitely not obscure the
clean cfg. syintax in any way.)

Another question: why is there no setenv() in the 
std. lib??? I add one myself to my stuff and seem 
to be using it with no immediately visible disastrous
consequences... 

(Sorry, I just started using LUA4 last night. 4
only for its Debian binary package. Any educated 
guesesses on newer liblua.deb releases? This LUA
thing started getting my sympathy.)

Thanks very much for any hints!
Sab

Reply | Threaded
Open this post in threaded view
|

Re: Environment variables

Peter Hill-2
Szabolcs Szasz:
> I need to support a simple config file written
> consisting purely of
>     variable = "value"
(snip)
> I thought of using a tagmethod for setglobal, but
> that did not seem to be allowed. Also, the globals
> table is of not much help now (I guess).

Globals table should be fine in Lua4 (it's Lua5 that has a new way of doing
things that may take a bit of thinking).

I would expect the following would work fine:

  function f(configfile)
    -- as locals these become immune to changing the global table.
    local dofile = dofile
    local globals = globals

    -- New empty global table (store old globals in glob).
    local glob = globals({}) 

    -- Load the new globals with the config data.
    dofile(configfile)

    -- Reset to the old globals, the new data is safe in glob.
    glob = globals(glob)

    -- Return the config data.
    return glob
  end

*cheers*
Peter Hill.



Reply | Threaded
Open this post in threaded view
|

Re: Environment variables

Luiz Henrique de Figueiredo
In reply to this post by Szabolcs Szasz
>I thought of using a tagmethod for setglobal, but
>that did not seem to be allowed. Also, the globals 
>table is of not much help now (I guess).

The "setglobal" tagmethod for nil should work fine for Lua 4.0.
For Lua 5.0, use the "__newindex" metamethod.

>Another question: why is there no setenv() in the 
>std. lib???

Because it's not ANSI C. The man page in my Linyx box says that setenv is
only in BSD 4.3, not even in POSIX, which seems to have putenv.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Environment variables

David Jones-2
In message <200302090008.WAA31048@...>, Luiz Henrique de Fig
ueiredo writes:
> 
> >Another question: why is there no setenv() in the 
> >std. lib???
> 
> Because it's not ANSI C. The man page in my Linyx box says that setenv is
> only in BSD 4.3, not even in POSIX, which seems to have putenv.

Of course, you are quite right, setenv is not in ANSI C.

Your Linux man pages are incorrect (surprise!).

setenv is in POSIX, see
http://www.opengroup.org/onlinepubs/007904875/toc.htm (or in IEEE
Std 1003.1-2001 which passes for POSIX these days at any rate).

putenv is in the same standard, but is XSI shaded (IE not part of
the core and only supported on XSI conformant systems).  Also, the
same standard says in the Application Usage section: "The setenv()
function is preferred over this function".  See
http://www.opengroup.org/onlinepubs/007904875/toc.htm

Cheers,
 drj

Reply | Threaded
Open this post in threaded view
|

Re: Environment variables (setenv/putenv)

Szabolcs Szasz
Thanks very much for the comments, first of all!

> > >Another question: why is there no setenv() in the 
> > >std. lib???
> > 
> > Because it's not ANSI C. The man page in my Linyx box says that setenv is
> > only in BSD 4.3, not even in POSIX, which seems to have putenv.
> 
> Of course, you are quite right, setenv is not in ANSI C.
> 
> Your Linux man pages are incorrect (surprise!).
> 
> setenv is in POSIX, see


;) Well, rephrasing the question then a bit...:

Is the natural pair of getenv(), by whatever name,
available in LUA? I could not find it.

If it really is missing, is there any _good_ reason
for not adding it (again, by whatever name)?

Thanks,
Sz.

Reply | Threaded
Open this post in threaded view
|

Re: Environment variables (setenv/putenv)

Björn De Meyer
Szabolcs Szasz wrote:
> 
> ;) Well, rephrasing the question then a bit...:
> 
> Is the natural pair of getenv(), by whatever name,
> available in LUA? I could not find it.
> 
> If it really is missing, is there any _good_ reason
> for not adding it (again, by whatever name)?
> 

Well, setenv() or putenv() are not directly available, but, 
you can dd the yourself. The good reason for not including them
is that core of Lua has alway been written in (a subset of) 
pure ANSI 89 C, without allowing any non-ANSI extensions in 
the core. If we want non-ansi extensions, we add them ourselves.

-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Environment variables (setenv/putenv)

Szabolcs Szasz
> > Is the natural pair of getenv(), by whatever name,
> > available in LUA? I could not find it.
> > 
> > If it really is missing, is there any _good_ reason
> > for not adding it (again, by whatever name)?
> > 
> 
> Well, setenv() or putenv() are not directly available, but, 
> you can dd the yourself. The good reason for not including them
> is that core of Lua has alway been written in (a subset of) 
> pure ANSI 89 C, without allowing any non-ANSI extensions in 
> the core. If we want non-ansi extensions, we add them ourselves.

Thanks. I already added it myself, that's exactly why 
I got pissed. :) So, ANSI 89 C is the guilty one... 

Now, just a side-note: I added the missing function to 
my LUA API presented to the clients of my platform, but 
hesitated long whether to prefix that function with my 
standard API prefix, or not. Finally I decided not to. 
This is impure, and itching, but how would it look 
in the client code to mg_putenv() something, and then
just getenv() it back at some other place?

So, it would be so nice if sometimes platform layers, 
were "bold" enough to even out some of the unevenness 
instead of following "faithfully" the bumps and pits 
of the underlying layers.

Sab

Reply | Threaded
Open this post in threaded view
|

Idea: Lua Max, a complete standalone Lua

Björn De Meyer
In reply to this post by Björn De Meyer
This is an idea I have been toying with for a while, 
and I wish to throw it into the group to see if there 
is interest for it. 

Lua is a nice language, especially for embedding. 
With Lua 5 we get many nice features that make embedding
However, I feel Lua should also be used more commonly
as a standalone language. For that, I believe more 
functionality will be needed. 

My idea is then for us Lua users to make a Lua Max 
(or the same thing under another another name) wich 
is a standalone Lua which comes with many useful, 
yet mostly portable libraries built in. The target 
platforms would be Posix, X Window, and Microsoft 
Windows platforms. Included in this LuaMAX could be: 

* Loadlib dynamic library support.
* A lightweight GUI toolkit, probably FLTK.
* SQL functionality.
* Complete regular expressions.
* Assistance for CGI, web-based programming.
* PThreads.
* Sockets.
* Extended math.
* Directory handling, filesystem manipulation.
* zlib compression support.
* Lua script repository that facilitates common 
  tasks such as OOP/inheritance programming.
* Etc, etc.

Does this interest anyone here enough to help me 
put some effort in this idea? I could only handle the
Linux ports, Windows would be for someone else.


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Lua Max, a complete standalone Lua

Martin Spernau
Well, for Lua4 something similar almost exists.
Using the BinaryModuleLoding supplied by the loadmodule.c patch, I have a
Lua4 that has
* SQLite (embeded SQL engine, no dependecies on external DBs)
* Sockets
* XML handling
* zlib
* PCRE regex (not real good binding yet, in dev)
and I experimentally combinded this extended Lua with wxLua, which seems to
work, but I haven't tested that really well

All this should compile on all mentined plattforms (I only use Windows
myself)

The thing is, I'm waiting for the various module authors to bring out Lua5
versions, so my own efforts are a little halted for now.

Point being, YES I'd be interested in such a thing, esp. if it can be keept
cross-platform and modular.
Modularity is a important point to me, as I'd very much like to share code
between different 'stages' of applications. A GUI app should be able to use
the same script modules as a 'faceless' console/server app etc.

-Martin
----- Original Message -----
From: "Björn De Meyer" <[hidden email]>
To: "Multiple recipients of list" <[hidden email]>
Sent: Sunday, February 09, 2003 2:03 PM
Subject: Idea: Lua Max, a complete standalone Lua


> This is an idea I have been toying with for a while,
> and I wish to throw it into the group to see if there
> is interest for it.
>
> Lua is a nice language, especially for embedding.
> With Lua 5 we get many nice features that make embedding
> However, I feel Lua should also be used more commonly
> as a standalone language. For that, I believe more
> functionality will be needed.
>
> My idea is then for us Lua users to make a Lua Max
> (or the same thing under another another name) wich
> is a standalone Lua which comes with many useful,
> yet mostly portable libraries built in. The target
> platforms would be Posix, X Window, and Microsoft
> Windows platforms. Included in this LuaMAX could be:
>
> * Loadlib dynamic library support.
> * A lightweight GUI toolkit, probably FLTK.
> * SQL functionality.
> * Complete regular expressions.
> * Assistance for CGI, web-based programming.
> * PThreads.
> * Sockets.
> * Extended math.
> * Directory handling, filesystem manipulation.
> * zlib compression support.
> * Lua script repository that facilitates common
>   tasks such as OOP/inheritance programming.
> * Etc, etc.
>
> Does this interest anyone here enough to help me
> put some effort in this idea? I could only handle the
> Linux ports, Windows would be for someone else.
>
>
> --
> "No one knows true heroes, for they speak not of their greatness." --
> Daniel Remar.
> Björn De Meyer
> [hidden email]
>


Reply | Threaded
Open this post in threaded view
|

Re: Environment variables (setenv/putenv)

Björn De Meyer
In reply to this post by Szabolcs Szasz
Szabolcs Szasz wrote:
> Thanks. I already added it myself, that's exactly why
> I got pissed. :) So, ANSI 89 C is the guilty one...
> 
> Now, just a side-note: I added the missing function to
> my LUA API presented to the clients of my platform, but
> hesitated long whether to prefix that function with my
> standard API prefix, or not. Finally I decided not to.
> This is impure, and itching, but how would it look
> in the client code to mg_putenv() something, and then
> just getenv() it back at some other place?
> 
> So, it would be so nice if sometimes platform layers,
> were "bold" enough to even out some of the unevenness
> instead of following "faithfully" the bumps and pits
> of the underlying layers.

Well, in Lua, function names are irrelevant. 
do a mg_putenv = putenv, and your clients will have the 
choice of how to call the function. Oh, and to be 
forwardly compatible with the ideas of Lua 5, I suggest 
that in stead of using a prefix "mg_", you use a table
"mg" and put all your functions in there. then, your end users 
will be able to say mg.putenv(), which is much like 
os.getenv() in Lua 5. 

As for having a Lua that is more "bold", please 
read my other mail. The official Lua should remain small,
but that doesn'nt mena we can't make a "big, bold" 
Lua ourselves. ^_^


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Idea: Lua Max, a complete standalone Lua

Euler German
In reply to this post by Björn De Meyer
On 9 Feb 2003, at 14:03, Björn De Meyer wrote:


-<snip>-
> 
> Does this interest anyone here enough to help me 
> put some effort in this idea? I could only handle the
> Linux ports, Windows would be for someone else.
> 

Sure! You'll have my effusive applause. I just dunno if I could be of 
some help. Anyway, I'm willing to offer my poor (very poor) skills.

-- Euler
--
 /"\  The ASCII ribbon      | Euler GERMAN
 \ /  campaign against HTML | Caixa Postal 232
  X   eMail, HTML news, and | 35701-970 Sete Lagoas, MG, Brasil
 / \  unneeded MIME.        | PGP key ID: 0x92D7247F

Reply | Threaded
Open this post in threaded view
|

Re: Lua Max, a complete standalone Lua

Björn De Meyer
In reply to this post by Martin Spernau
Martin Spernau wrote:
> 
> Well, for Lua4 something similar almost exists.
> Using the BinaryModuleLoding supplied by the loadmodule.c patch, I have a
> Lua4 that has
> * SQLite (embeded SQL engine, no dependecies on external DBs)
> * Sockets
> * XML handling
> * zlib
> * PCRE regex (not real good binding yet, in dev)
> and I experimentally combinded this extended Lua with wxLua, which seems to
> work, but I haven't tested that really well
> 
> All this should compile on all mentined plattforms (I only use Windows
> myself)
> 
> The thing is, I'm waiting for the various module authors to bring out Lua5
> versions, so my own efforts are a little halted for now.
> 
> Point being, YES I'd be interested in such a thing, esp. if it can be keept
> cross-platform and modular.
> Modularity is a important point to me, as I'd very much like to share code
> between different 'stages' of applications. A GUI app should be able to use
> the same script modules as a 'faceless' console/server app etc.
> 

That is versy interesting. Yes, I am waiting for the release of 
Lua 5 and tolua 5 as well.I think this LUAMAX should be based 
on the most recent official Lua version available.

Yes, Modularity is also important, I forgot to think about 
that that. Just as you have io, os, table, etc modules in Lua 5, 
you'd have fltk, wxwin, sqlite, thread, socket, sql, etc. 
I'm mostly a Linux programmer, so we have already 2 platforms 
"covered" if we work together.


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
[hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Lua Max, a complete standalone Lua

Martin Spernau
----- Original Message -----
From: "Björn De Meyer" <[hidden email]>
> Yes, Modularity is also important, I forgot to think about
> that that. Just as you have io, os, table, etc modules in Lua 5,
> you'd have fltk, wxwin, sqlite, thread, socket, sql, etc.
> I'm mostly a Linux programmer, so we have already 2 platforms
> "covered" if we work together.

Cool!



Reply | Threaded
Open this post in threaded view
|

CGILua

Martin Spernau
In reply to this post by Björn De Meyer
Regarding CGILua,
I searched the lua-l archives and came up with a pointer to
http://www.inf.puc-rio.br/~ana/cgilua/
which is for Lua4.
(http://www.inf.puc-rio.br/~ana/cgilua/cgilua-4.0.3pre.tgz)
The 'official' CGILua linked from the Wiki is for Lua3.2...

Question: what is the status of CGILua?

And a note to anybody interested in doing CGI (or HTTP GET/POST) related
stuff, there'S some nice Lua Scripts in that package for decoding GET/POST
data.
Very usefull!
(Maybe one could extract them and put them in the Lua standard Library pages
on the Wiki?)

-Maritn






Reply | Threaded
Open this post in threaded view
|

Re: Idea: Lua Max, a complete standalone Lua

Peter Shook-5
In reply to this post by Björn De Meyer
On Sunday 09 February 2003 08:03, Bjorn wrote:
>
> Does this interest anyone here enough to help me
> put some effort in this idea? I could only handle the
> Linux ports, Windows would be for someone else.

I can help, but my interest diminishes considerably when it comes to M$ 
Windows.

- Peter Shook

Reply | Threaded
Open this post in threaded view
|

Re: Lua Max, a complete standalone Lua

Peter Hill-2
In reply to this post by Björn De Meyer
Björn De Meyer:
> Yes, Modularity is also important, I forgot to think about
> that that. Just as you have io, os, table, etc modules in Lua 5,
> you'd have fltk, wxwin, sqlite, thread, socket, sql, etc.

With Lua you often seem to have to choose between libraries being (a)
compiled into Lua, (b) a separate object file that is linked along with Lua
into the target program or (c) a dynamic library loaded with Loadlib etc.

These are all valid approaches and it thus seems a worthy goal to make the
source for each library such that, with a compiler option, the same source
can be compiled into each of these varieties.

*cheers*
Peter Hill.



Reply | Threaded
Open this post in threaded view
|

Re: CGILua

Peter Hill-2
In reply to this post by Martin Spernau
Martin Spernau:
> And a note to anybody interested in doing CGI (or HTTP GET/POST) related
> stuff, there'S some nice Lua Scripts in that package for decoding GET/POST
> data. Very usefull!
>
> (Maybe one could extract them and put them in the Lua standard Library
> pages on the Wiki?)

Now THAT (extraction to the Wiki) seems like a worthy goal for most Lua
systems & applications that are not propriety. Making a source library of
various useful modules that people have created as a part of their projects.

*cheers*
Peter Hill.



Reply | Threaded
Open this post in threaded view
|

Re: Idea: Lua Max, a complete standalone Lua

Juergen Fuhrmann
In reply to this post by Björn De Meyer
>  Sun, 09 Feb 2003 14:03:43 +0100
>  Björn De Meyer <[hidden email]> wrote:
>
[...]
>  
>  My idea is then for us Lua users to make a Lua Max 
>  (or the same thing under another another name) wich 
>  is a standalone Lua which comes with many useful, 
>  yet mostly portable libraries built in. The target 
>  platforms would be Posix, X Window, and Microsoft 
>  Windows platforms. Included in this LuaMAX could be: 
>
>  * Loadlib dynamic library support.
>  * A lightweight GUI toolkit, probably FLTK.
>  * SQL functionality.
>  * Complete regular expressions.
>  * Assistance for CGI, web-based programming.
>  * PThreads.
>  * Sockets.
>  * Extended math.
>  * Directory handling, filesystem manipulation.
>  * zlib compression support.
>  * Lua script repository that facilitates common 
>    tasks such as OOP/inheritance programming.

Good Idea! 

Basically,  IMHO we  need a  core Lua,  and some  more layers  of code
around it. The excellent Lua core  is there. But I think that we would
have a  much larger community  if there would  be a set  of canonincal
accompaniying tools. 


The problem  is that  my time is  very limited,  at the other  hand, I
cannot get my hands off lua, so let's see..

tolua would be nice to have there.


I am trying to set up a numerical analysis tool similar to matlab, but
for partial  differential equations, which  needs access to  huge data
sets and handling of "native" arrays. I could contribute in this area.

Juergen Fuhrmann

PS: How is "Full Moon" in Portuguese ? This would be my suggestion for
the name...

                             Numerical Mathematics & Scientific Computing
               Weierstrass Institute for Applied Analysis and Stochastics
   Mohrenstr. 39 10117 Berlin    fon:+49 30 20372560   fax:+49 30 2044975
http://www.wias-berlin.de/~fuhrmann        [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Idea: Lua Max, a complete standalone Lua

Roberto Ierusalimschy
> PS: How is "Full Moon" in Portuguese ? This would be my suggestion for
> the name...

I know that!! "Lua Cheia" (pronounced more-or-less like "shay-ah"). I
would sugest the name LuaEE ("Enterprise Edition" ;-).

I really like this idea (whatever the name), but one thing that people
usually forget is documentation. Such distribution should include
documentation for all the modules included, in an as much as possible
uniform document.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Idea: Lua Max, a complete standalone Lua

Juergen Fuhrmann
In reply to this post by Juergen Fuhrmann
>  
>  I am trying to set up a numerical analysis tool similar to matlab, but
>  for partial  differential equations, which  needs access to  huge data
>  sets and handling of "native" arrays. I could contribute in this area.
>  

BTW I could contribute with  Tru64 Unix, Irix, Linux/icc, Solaris, HP,
Linux/AXP and possibly AIX builds.  I  have Lua running on those and I
am definitively interested in portability under Linux.


Juergen



123