[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Can I template the filename for io.tmpfile()
- From: Steve Litt <slitt@...>
- Date: Wed, 12 Jan 2011 01:34:37 -0500
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.
Recession Relief Package