lua-users home
lua-l archive

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


Hi all,

The docs on io.tmpfile are pretty sparse, and before I roll my own let me ask.

I basically want a Lua equivalent to the Linux command mktemp, that does:

1) Construct an unused filename from a template of my choosing (like 
steve.xxxxxxx where each x is a place for a random number
2) Open the file for write
3) Return the filename to me so after I complete writing to the file and close 
it, I can execute it.

I want part of the filename to be recognizeable so I can os.execute() it, and 
for debugging I can find it in the operating system later. Any way I can do 
this with io.tmpfile?

If all else fails, how can I seed the random number generator? os.time() is 
useless because I expect lots of people to start up with that same number of 
seconds. Time plus username is better, but it's conceivable I could start two 
instances in the same second. I was unable to get the PID of my Lua program in 
any quick way other than executing a command to do a ps, write it to a file, 
and read the file, and that's too slow because I want the user experience to 
be instantaneous (and it is if I don't do all this spawning and reading). 
There must be something different about each invocation of a Lua program.

Thanks

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt