MirthKit Dictionary
From MirthKit
This is a list of all of the functionality available in MirthKit. Functions range from drawing, to sound, to networking, to input, and more. They are all global-scope functions; MirthKit's API is not object oriented.
Contents |
[edit] Overview
This is a list of all of the functionality in MirthKit. Click blue links to view more information on a function (red ones don't have a full documentation page yet -- feel free to add one before we do). For more information about the Squirrel language, see the project's website, http://www.squirrel-lang.org.
[edit] Control
[edit] MirthKit Functions
- update() - Updates internal subsystems. Returns width and height of the screen in an array.
- flush() - Flushes all internal subsystem caches.
- progress(current,total) - Sets the http download screen to display a particular progress. Pass -1,-1 to reset to default progress mode.
- version() - Returns an array containing major and minor version numbers.
- background(red,green,blue) - Sets the color that update() clears to.
[edit] Code Generation
- doNut(filepath) - Very important! This is how you make MirthKit aware of code in other files. Like #include in C++ and import in Java.
- loadNut(filepath) - Compiles a nut file and returns the compiled file as a function.
- compilestring(string) - Compiles the squirrel code inside string into a returned function.
[edit] Time
- millis() - Returns the current time in milliseconds.
- micros() - Returns the current time in microseconds.
[edit] Graphics
[edit] Drawing
- line(startX,startY,endX,endY) - Draw a line.
- rect(x,y,width,height) - Draw a rectangle.
- text(string,x,y,width) - Draw text that wraps after width pixels. Returns the y position immediately after the text.
- cursorText(string,x,y,width,cursorX,cursorY) - Draw a block of text in multiple function calls and get more precise measurements about a block of text.
[edit] Transform
- modifyWindow(x,y,width,height,scale,rotation,masking) - Use this to rotate, scale, and move anything drawn afterwards.
- revertWindow() - Returns to the coordinate system used before the last modifyWindow(...).
[edit] Brush
- modifyBrush() - Use a new brush which is a copy of the current brush.
- revertBrush() - Return to the brush used before the last modifyBrush().
- fillColor(red,green,blue,alpha) - Set the current color of any fill.
- lineColor(red,green,blue,alpha,width) - Set the current color of any lines.
- image(filepath,repeatX,repeatY) - Set an image to fill with. Returns an array containing the width and height of the image.
- font(filepath,size) - Set the ttf font file to draw text with.
- additiveBlending(useIt) - Set the blending mode to addition, which is good for simulating light. False sets to the blending mode to modulate.
[edit] Advanced Triangles
- beginTriangles() - Starts a set of triangles to draw.
- endTriangles() - Ends a set of triangles.
- vertex(x,y) - Specifies a vertex of a triangle.
- textureCoord(u,v) - Specifies a texture mapping coordinate for future vertices. Use image(...) to specify the desired texture.
[edit] Sound
- sound(filepath,angle,distance) - Plays a sound with 2D positioning. Wav format only. Angle is in degrees, starting from up, rotating clockwise. Distance ranges from 0 to 1.
- music(filepath) - Stereo music can be in ogg or wav format.
- soundVolume(volume) - Sets the volume for future sounds.
- musicVolume(volume) - Sets the volume for the currently playing music.
- musicFade(volume,seconds) - Transitions to the given volume over the given time span.
[edit] Input
[edit] Mouse
- mouse() - Returns an array with the position of the mouse.
- mouseButton(buttonNumber) - Returns whether the button is currently pressed. Left=1, Middle=2, Right=3
- cursor(showCursor) - Show the opperating system's cursor or not. This will not lock the mouse to inside of the window.
[edit] Keyboard
- key(keyCode) - Returns whether the key is currently pressed. ASCII codes directly map to their keyCode equivallent.
- rawKey(keyCode) - Returns whether the key is currently pressed. This doesn't go through the binding system as the above function does.
- keyCode(keyName) - Find what the code of a key is. KeyNames are in all caps.
- keyName(keyCode) - Get the name of a key from its key code.
- catchKey() - Returns the keyCode of a key that is currently pressed. If you don't know the keyName of a key, use this in a test program to find it.
- catchType() - Returns a list of the keys that are currently being pressed. (array of keyCodes)
- modifiedKey(keyCode) - Returns keyCode, but as a shift-filtered ascii character, represented as an integer. It converts letters to uppercase, and numbers to their qwerty-shifted equivalents. Use .tochar() on the integer to process it with strings.
- bind(keyCode,bindedKeyCode) - Whenever keyCode is pressed in the future, key(...) will actually return that bindedKeyCode is pressed.
- binding(keyCode) - Returns what key keyCode is bound to.
[edit] Data Processing
[edit] Command Line Output
- print(string) - Prints the string to the command line (stdout.txt in MirthKit's executable directory). Great for debugging.
[edit] Networking
- open(socketName,port) - Opens a socket on the specified port, which will be refered to by socketName.
- close(socketName) - Closes an open socket.
- send(socketName,remoteAddress,remotePort,dataString) - Sends a string to remoteAddress's port.
- receive(socketName) - If anything needs to be received, it returns an array containing the address this message came from, the port this message came from, and a string containing the actual message. If nothing needs to be received, it returns null.
[edit] HTTP
- http(url) - Returns the specified url's response in a string. This function does not cache results.
[edit] Persistent Storage
- store(vaultName,name,value) - Stores a named value in a vault file.
- retrieve(vaultName,name) - Returns a stored value from a vault file.
[edit] Compression
- compress(string,level) - Compresses a string and returns the result as an encoded binary string.
- decompress(data) - Returns compressed data to its original format as a returned string.
[edit] Encryption
- hash(string) - Returns a cryptographic hash of the string.
- encrypt(string,password) - Encrypts a string and returns the result as an encoded binary string.
- decrypt(data,password) - Decrypts encrypted data and returns the result string.
[edit] File Input/Output
These functions are only loaded while Developer Mode is active. They are designed to be used for level editors or similar.
- readfile(filename) - returns a string containing the contents of the file.
- writefile(filename,string) - writes a string to a file, replacing all previous contents.
[edit] Basic User Interface
[edit] Strips
- guiNewStrip(width,height,marginX,marginY,paddingX,paddingY) - Creates a new gui strip. -1 for any value inherits from the previous strip.
- guiPreviousStrip() - Reverts to last strip before the previous guiNewStrip(...).
- guiOriginStrip() - Has the same effect as using guiPreviousStrip(...) for every existing strip.
- guiStripFill(red,green,blue,alpha) - Sets the fill color of the next new strip.
- guiStripBorder(red,green,blue,alpha,width) - Sets the line color of the next new strip.
- guiMoveDown() - Sets the next strip to be directly below the current strip. This state is default
- guiMoveRight() - Sets the next strip to be directly to the right of the current strip.
- guiMoveUp() - Sets the next strip to be directly on top of the current strip.
- guiMoveLeft() - Sets the next strip to be directly to the left of the current strip.
[edit] Content
- guiText(string,verticalMargin) - Draw a new text block at this box's cursor.
- guiImage(filepath,width,height,verticalMargin) - Draw an image at this box's cursor. -1 for width or height will draw the image at its native resolution.
[edit] Buttons
- guiBeginButton(buttonName,verticalMargin) - Put content inside a begin/end button to know if the mouse interacts with them. This function returns the previous state of this button.
- guiEndButton() - Returns the current state of the button. Button states: Off=0, Over=1, JustDown=2, Down=3, JustUp=4
- guiButtonUpBorder(red,green,blue,alpha,width) - Sets the color of a button's border when it is not interacting with the mouse.
- guiButtonOverBorder(red,green,blue,alpha,width) - Sets the color of a button's border when the mouse is on top of the button.
- guiButtonDownBorder(red,green,blue,alpha,width) - Sets the color of a button's border when the button is clicked.
[edit] Language
[edit] Most Objects
- object.tofloat() - Attempts to convert the object to a float.
- object.tointeger() - Attempts to convert the object to an integer.
- object.tostring() - Attempts to convert the object to a string.
- object.tochar() - Converts numbers to their ascii character, which can then be added to strings.
- object.weakref() - Returns a reference object.
[edit] String
- string.len() - Returns the length of the string.
- string.slice(startIndex,endIndex) - Returns the portion of a string beginning at startIndex and ending before endIndex.
- string.find(substring,startIndex) - Searches for substring starting from startIndex and returns the index of its first occurrence or null if not found.
- string.tolower() - Converts all uppercase letters in a string to lowercase, returning the result.
- string.toupper() - Converts all lowercase letters in a string to uppercase, returning the result.
[edit] Table
- table.len() - Returns the length of the table.
- table.clear() - Removes all the contents of the table.
[edit] Array
- array.len() - Returns the length of the array.
- array.append(object) - Adds object to the end of the array.
- array.extend(otherArray) - Adds all of the objects in otherArray to this array.
- array.pop() - Removes the last object in the array, returning it.
- array.top() - Returns the last object in the array.
- array.insert(index,object) - Adds object to the array at the specified index.
- array.remove(index) - Removes the the object at the specified index.
- array.resize(size, fill) - Resizes the array, inserting fill into any new indexes created.
- array.sort(compareFunction) - compareFunction(a,b) must return 0 for equality, 1 if a is greater, or -1 if b is greater.
- array.reverse() - Reverses the order of the array.
- array.slice(startIndex, endIndex) - Returns the portion of the array beginning at startIndex and ending before endIndex in a new array.
- array.clear() - Removes all the contents of the array.
[edit] Squirrel Information
For information about the language used in these examples, see Squirrel.
