| Lua os functions |
|---|
| Lua os functions These are the functions in the "os" table. Some of these functions are disabled by default in the MUSHclient "Lua sandbox". Check that out if you plan to use the "os" functions. os.clock () Returns the approximate amount of CPU time used by the current process in seconds. os.date (format, time) Returns a string with the date and time formatted according to the format given. If no time is supplied defaults to the current time. The format string can consist of literal strings, mixed with the following directives: The # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows. Examples: os.difftime (t1, t2) Returns the number of seconds from time t1 to time t2. os.execute (command) Passes 'command' to the operating system shell for execution. Returns a status code. Here is a method of capturing the output to a file, and reading it in: os.exit (n) Terminates the host program with the return code n. However, os.exit is doest not do that in MUSHclient. It will raise an error if called. This is because doing an immediate exit bypasses all checks to save open documents, save plugin states, and so on. os.getenv (v) Returns the environment variable v, or nil if undefined. os.remove (filename) Deletes the file. On success, returns true. If it cannot, it returns nil followed by an error message. os.rename (oldname, newname) Renames a file. On success, returns true. If it cannot, it returns nil followed by an error message. os.setlocale (locale, category) Sets the current locale to the supplied locale. Category, which is optional, is a string which is one of:
Returns the name of the new locale, or nil if invalid. Hint: I found that in Australia, the default in Lua was to use the USA time format (MM/DD/YY) rather than the local format (DD/MM/YY) when displaying dates with os.date. This line seemed to fix that: According to the help file "If locale points to an empty string, the locale is the implementation-defined native environment.". Thus the empty locale string seemed take the country default. os.time (t) Returns the current time if no argument supplied. The time is in seconds from the start of the current epoch. On Windows, the function returns the number of seconds elapsed since midnight (00:00:00), January 1, 1970, coordinated universal time, according to the system clock. If an argument is supplied it must be a table with at least the entries:
The table can also have the entries:
This table can be produced by calling: os.date ("*t") os.tmpname () Returns a string with a name for a temporary file. Considered unsafe in an untrusted environment because someone may substitute a different file for the one whose name is returned to you, in the small window of time between obtaining the file name, and opening the file. See Also ... Topics
Lua base functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua math functions
Lua package functions
Lua script extensions
Lua string functions
Lua table functions(Help topic: general=lua_os)
Documentation contents page |