Misc Functions

From SolarStrike wiki
Revision as of 09:31, 15 July 2008 by Elverion (talk | contribs) (New page: == args == The 'args' table holds command-line-like data that is passed to the script when it is executed. The first argument (args[1]) will always be the script name as typed by the use...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

args

The 'args' table holds command-line-like data that is passed to the script when it is executed.

The first argument (args[1]) will always be the script name as typed by the user, while the rest of the arguments are tokenized by spaces. That is, if you run the script "test.lua testing 123", args[1] contains the script name ("test.lua"), args[2] contains "testing" and args[3] contains the number 123.


Example

-- Assume the user typed in: script.lua something
if( args[2] ) then
  -- They have added an argument to the script call.
  if( args[2] == "something" ) then
    -- The user wants us to do something!
    do_something();
  end
end


rest

rest(time)

Causes the macro to pause for some 'time' milliseconds (1/1000th of a second).


Example

rest( 1000 ); -- 1 second will elapse before continuing.


pluginInstalled

pluginInstalled(name)

Returns true if a plugin with the given name is installed. You should not include the ".dll" extension. Plugin checks are not case sensitive.


Example

if( pluginInstalled("myplugin") ) then
  printf("MyPlugin is successfully installed.\n");
end


setPriority

setPriority(priority)

Sets the macro interpreter's priority. You should pass in one of following variables: priority.high, priority.normal, or priority.low. Use this to overcome processes fighting over timeslice. If you don't understand what this does, you probably won't need it.


Example

setPriority(priority.high);


logMessage

logMessage(message)

Adds a formatted log message (string only) to the log file. Follows the format: "{time} : {message}\n", where {message} is a string containing the text you want logged. The newline marker is automatically appended.

If you would like to format your own messages, see logRaw().


Example

logMessage("This is an example logged message.");


logRaw

logRaw(message)

Adds a message (string or number) directly to the log file without formatting. You may use this function to format your own messages.


Example

logRaw("My favorite number is ");
logRaw(12);
logRaw("\n");


getVersion

getVersion()

Returns MicroMacro's version number as an integer. A value of 100 would be equivilent to version 1.0, or a value of 95 would be equivilent to version 0.95. This can be used to check whether or not an end user's version of MicroMacro supports functions in a script you are designing. You can use division and modulo to separate the major and minor version numbers from the value returned, as done in the example.


Example

version = getVersion();
major = math.floor(version / 100);
minor = version % 100;
io.write("MicroMacro v", major, ".", minor, "\n");

-- This will print (assume we are using micromacro 1.0):
-- MicroMacro v1.0