Skip to content
IgorTimofeev edited this page Jan 24, 2019 · 12 revisions

This library is the core of the operating system and allows you to manage it at a basic level. Below are only the most necessary methods due to my laziness to create documentation, however, those that are available will be quite enough for most developers.

Auxiliary methods

system.getTime(): float timestamp

Returns real world Unix timestamp of current system using timezone defined in user properties.

os.date("%d %b %Y %H:%M:%S", system.getTime())
> 13 Jan 2019 05:10:32

system.getCurrentScript(): string path

Returns path to currently running script. For example, if you create file named /MineOS/Scripts/Test.lua and call this function from it, the following string will be returned:

> /MineOS/Scripts/Test.lua

system.getTemporaryPath(): string path

Returns temporary directory with random name. It will be erased on next MineOS boot.

system.parseArguments(...): table arguments, table options

Method for programs to parse their arguments. Returns two tables, the first one containing all incoming arguments, the second containing options. Options must be indicated by a leading -, and all options must only be a single character, since multiple characters following a single - will be interpreted as multiple options. Options specified with 2 dashes are not split and can have multiple letters. Also, 2-dash options can be given values by using an equal sign. The following example will show how this function works:

system.parseArguments("meow", "-purr", "--purr", "--meow=purr", "-meow=purr")
> {
    "meow"
  },
  {
    "p"
    "u"
    "r"
    "purrr"
    meow = "purr",
    "m"
    "e"
    "o"
    "w"
    "="
  }

Shortcuts

system.createShortcut(string wherePath, string forWhatPath)

Creates an shortcut with .lnk extension by given where path. Shortcut points to a file or directory located on given forWhat path.

system.createShortcut(
	"/MineOS/Users/MyName/Desktop/MyShortcut",
	"/MineOS/Pictures/Dick.pic"
)

system.readShortcut(string shortcutPath): string targetPath

Reads shortcut located by given shortcutPath and returns a string targetPath it points to:

system.readShortcut("/MineOS/Users/MyName/Desktop/MyShortcut.lnk")
> "/MineOS/Pictures/Dick.pic"

User methods

system.getUser(): string username

Returns currently logged in user name.

system.getUser()
> Herobrine1488

system.saveUserSettings()

Writes currently logged in user settings table to a %user_path%/Settings.cfg file.

system.getUserSettings(): table settings

Returns currently logged in user settings table. You can change it's keys and values whatever you want and call system.saveUserSettings() method.

local settings = system.getUserSettings()

settings.interfaceWallpaperPath = "/Dick.pic"
settings.localizationLanguage = "Russian"

system.saveUserSettings()

system.authorize()

Moves user to authorization interface stage:

Localization methods

system.getLocalization(string path): table localization

Searches for files with .lang extension in directory by given path and returns an deserialized table. Priority is given to the language that is set in currently logged in user properties. If required language is not found, this function tries to load English.lang file. If it is not found, function tries to load the first available file. If the directory by given path is empty, an error occurs.

system.getLocalization("/Robot.app/Localizations/")
> {
    greeting = "Hello",
    robot = "This is my robot"
  }

system.getCurrentScriptLocalization(): table localization

Works the same way as system.getLocalization() does, but automatically searches for appropriate localization file in Localizations/ directory located near currently running script:

Sample.app/
	Main.lua
	Localizations/
		English.lang
		Russian.lang

system.getSystemLocalization(): table localization

Returns currently logged in user system localization table.

Interface methods

system.getWorkspace(): table workspace

Returns pointer to main GUI.workspace object that is currently being used by MineOS. This workspace contains every OS visual element: top menu object, windows container, dock widget, icon field, icons, etc.

system.addWindow(table window[, boolean keepCoordinates]): table workspace, table window, table menu

Adds instance of GUI.window object to MineOS windows container, adds corresponding icon to dock and adds window menu data. If keepCoordinates argument is set, window coordinates will be kept, otherwise window will be centered. Returns pointer to main system GUI.workspace object, a pointer to given window object and a pointer to system GUI.menu object:

-- Import libraries
local GUI = require("GUI")
local system = require("System")

---------------------------------------------------------------------------------

-- Add a new window to MineOS workspace
local workspace, window, menu = system.addWindow(GUI.filledWindow(1, 1, 60, 20, 0xE1E1E1))

-- Add single cell layout to window
local layout = window:addChild(GUI.layout(1, 1, window.width, window.height, 1, 1))

-- Add nice gray text object to layout
layout:addChild(GUI.text(1, 1, 0x4B4B4B, "Hello, " .. system.getUser()))

-- Customize MineOS menu for this application by your will
local contextMenu = menu:addContextMenuItem("File")
contextMenu:addItem("New")
contextMenu:addSeparator()
contextMenu:addItem("Open")
contextMenu:addItem("Save", true)
contextMenu:addItem("Save as")
contextMenu:addSeparator()
contextMenu:addItem("Close").onTouch = function()
	window:remove()
end

-- You can also add items without context menu
menu:addItem("Example item").onTouch = function()
	GUI.alert("It works!")
end

-- Create callback function with resizing rules when window changes its' size
window.onResize = function(newWidth, newHeight)
  window.backgroundPanel.width, window.backgroundPanel.height = newWidth, newHeight
  layout.width, layout.height = newWidth, newHeight
end

---------------------------------------------------------------------------------

-- Draw changes on screen after customizing your window
workspace:draw()

Result:

How to develop MineOS applications?

Every MineOS application is a directory with .app extension, which has the following contents:

2019-01-08 11 03 18

The Main.lua file is launched on application start, and Icon.pic is used to display application icon. Application directory is very convenient to store some resources: localization files, images, configs, etc.

You can click on the corresponding option in the context menu to create sample application:

2019-01-08 11 31 24

When application directory is created, it's a good time to read wiki of how to use system APIs. You can instantly edit Main.lua file to do some source code changes:

2019-01-08 11 19 32

2019-01-08 11 17 46

2019-01-08 11 15 53

Clone this wiki locally