files
syscalls/doc/manual.md

590 lines
7.8 KiB
Markdown

# Manual
This is KolibriOS lua syscalls library. Usually you shouldn't use this library
Better if you read before [KolibriOS syscalls wiki](http://wiki.kolibrios.org/wiki/)
include this library:
```lua
local syscalls = require("syscalls")
```
## Events
### SetEventMask(newMask)
### CheckEvent()
check [event](#events-list)
### WaitEvent()
Endless wait [event](#events-list)
### WaitEventTimeout(timeout)
Wait timeout 1/100 sec
return event or `nil`
### Events list
```lua
syscalls.Event.<EventName>
```
+ `Redraw`
+ `Button`
+ `Key`
+ `Desktop`
+ `Mouse`
+ `Network`
+ `IPC`
+ `Debug`
## Window
### CreateWindow(x, y, width, height, workColor, [style](#window-style), borderColor, titleColor)
Define window
`borderColor` and borderColor` only for FixSizes` and CanChangeSizes` (without skin styles) style.
### StartRedraw()
Start window redraw. Just call it before CreateWindow`
### EndRedraw()
End window redraw. Just call it after you done redraw window.
### ChangeWindow(newX, newY, newWidth, newHeight)
### FocusWindow(slot)
### UnfocusWindow(slot)
### SetWindowTitle(newTitle)
### GetSkinHeight()
return skin height.
### SetSkin(path)
return error code
### GetSkinTitleArea()
return table:
```lua
{
Left: number,
Right: number,
Top: number,
Bottom: number
}
```
### Window Style
```lua
syscalls.windowStyle.<Value>
```
+ `FixSizes`
+ `NoDraw` (you must draw window manually)
+ `CanChangeSizes`
+ `WithSkin` (usually use it)
+ `WithSkinFixSizes` (with skin, but window size fixed)
## Graphic
### Text encoding
```lua
syscalls.Encoding.<value>
```
+ `cp866`
+ `cp866_8x16`
+ `utf8`
+ `utf16`
### Text sizes
```lua
syscalls.textSize.<value>
```
+ `6x9` (cp866 only)
+ `8x16`
+ `12x18` (cp866 only)
+ `16x32`
+ `18x27` (cp866 only)
+ `24x36` (cp866 only)
+ `24x48`
+ `30x45` (cp866 only)
+ `32x64`
+ `36x54` (cp866 only)
+ `40x80`
+ `42x63` (cp866 only)
+ `48x72` (cp866 only)
+ `48x96`
+ `56x112`
+ `64x128`
### DrawText(text, xPos, yPos, textColor, [textScale](#text-sizes), textLen, backgroundColor, [encoding](#text-encoding))
### DrawTextFixSize(text, xPos, yPos, textColor, [textScale](#text-sizes), textLen, backgroundColor, [encoding](#text-encoding))
Draw text.
textSize, textLen, backgroundColor, encoding are optional.
### DrawLine(x1, y1, x2, y2)
### DrawRectangle(x, y, width, height, color)
### ReadPoint(x, y)
return color
## Buttons
### DefineButton(x, y, width, height, id, color)
### DeleteButton(id)
### GetButton()
return pressed button or `nil`
### SetButtonStyle([style](#button-styles))
Set buttons style
### buttons
button's ids that defined default by window with skin
```lua
syscalls.buttons.<Value>
```
+ `close`
+ `minimization`
### Button styles
```lua
syscalls.buttonStyle.<Value>
```
+ `Flat`
+ `Volume`
## Keyboard
### GetKey()
return:
+ `nil` if buffer empty
+ if hotkey return second number
+ if key pressed and key input mode is ascii return string(1 char), else return [scancode](#scancodes)
example:
```lua
local key, hotkey = syscalls.GetKey()
if key then
print("key pressed")
end
if hotkey then
print("hotkey pressed")
end
```
### SetKeyInputMode(mode)
by default is `ASCII`
### GetKeyInputMode()
return key input mode.
isn't syscall
### Scancodes
```lua
syscalls.scancode.<Value>
```
+ `A`
+ `B`
+ `C`
+ `D`
+ `E`
+ `F`
+ `G`
+ `H`
+ `J`
+ `K`
+ `L`
+ `M`
+ `O`
+ `P`
+ `Q`
+ `S`
+ `T`
+ `U`
+ `W`
+ `X`
+ `Y`
+ `Z`
+ `1`
+ `2`
+ `3`
+ `4`
+ `5`
+ `6`
+ `7`
+ `8`
+ `9`
+ `F1`
+ `F2`
+ `F3`
+ `F4`
+ `F5`
+ `F6`
+ `F7`
+ `F8`
+ `F9`
+ `F10`
+ `F11`
+ `F12`
+ `LeftShift`
+ `RightShift`
+ `LeftAlt`
+ `RightAlt`
+ `Tab`
## SystemColors
### SystemColors type
userdata
#### Fields
```lua
{
frameArea: number,
grabBar: number,
grabBarButton: number,
grabButtonText: number
grabText: number,
workArea: number,
workButton: number,
workButton: number,
workButtonText: number,
workGraph: number,
workText: number
}
```
#### Constructor
```lua
syscalls.SystemColors.new(
frameArea,
grabBar,
grabBarButton,
grabButtonText,
grabText,
workArea,
workButton,
workButton,
workButtonText,
workGraph,
workText
)
```
### GetSystemColors()
return [SystemColors](#systemcolors-type)
### SetSystemColors([SystemColors](#systemcolors-type))
## Threads
### ThreadInfo(pid)
return table:
```lua
{
name: string,
pid: number,
cpu_usage: number,
memused: number,
winXPos: number,
winYPos: number,
winXSize: number,
winYPos: number,
slotState: number,
windowState: number,
slotNumWindowStack: number,
posInWindowStack: number,
keyInputMode: number
}
```
### KillBySlot(slot)
### Slot states
```lua
syscalls.slotState.<Value>
```
+ `Running`
+ `Suspended`
+ `SuspendedWaitEvent`
+ `NormalTerm`
+ `ExceptTerm`
+ `WaitEvent`
+ `Free`
## Sockets
### OpenSocket([domain](#socket-types), [type](#address-families), [protocol](#ip-protocols))
return socket
```lua
local socket, err = syscalls.OpenSocket(
syscalls.SOCK.STREAM,
syscalls.AF.INET,
syscalls.IPPROTO.IP
)
if err then
print("Error", err)
else
print("Ok")
end
```
### CloseSocket(socket)
### PairSocket()
```lua
local first, second = PairSocket()
if first then
print("OK")
else
print("Error:", second)
end
```
### Bind(socket, address)
### Listen(socket, backlog)
### Connect(socket, address)
### Accept(socket, , flags)
### Receive(socket, , flags)
### SetSocketOption(socket, [opt](#socket-options))
### GetSocketOption(socket, [opt](#socket-options))
### Socket types
```lua
syscalls.SOCK.<Value>
```
+ `STREAM`
+ `RAW`
+ `DGRAM`
### Address families
```lua
syscalls.AF.<Value>
```
+ `UNSPEC`
+ `LOCAL`
+ `INET`
+ `INET4`
+ `INET6`
### IP options
```lua
syscalls.IP.<Value>
```
+ `TTL`
### IP protocols
```lua
syscalls.IPPROTO.<Value>
```
+ `IP`
+ `ICMP`
+ `TCP`
+ `UDP`
+ `RAW`
### Socket options
```lua
syscalls.SO.<Value>
```
+ `BINDTODEVICE`
+ `NONBLOCK`
## Debug
### Registers type
```lua
{
eax: number
ebx: number,
esp: number,
esi: number,
edi: number,
eip: number,
eflags: number
}
```
### DebugPutc(char)
Put char to debug board
### DebugPuts(text)
Put string to debug board
### GetRegisters(pid)
The process must be loaded for debugging (as stated in the general description).
return registers table
### SetRegisters(pid, [registers](#registers-type))
The process must be loaded for debugging (as stated in the general description).
### Disconnect(pid)
The process must be loaded for debugging (as stated in the general description).
If the process was suspended, it resumes execution.
### Stop(pid)
The process must be loaded for debugging (as stated in the general description).
### Continue(pid)
The process must be loaded for debugging (as stated in the general description).
### ReadFromMem(pid, bytes, pointer, buffer)
The process must be loaded for debugging (as stated in the general description).
return or `nil`
### WriteToMem(pid, bytes, pointer, buffer)
The process must be loaded for debugging (as stated in the general description).
return or `nil`
### Done(pid)
### DefineBreakpoint(pid, index, condition, len)
### UndefBreakpoint(pid, index, condition, len)
## IPC
### DefineIPCBuffer(size)
Define buffer for IPC receive
Return [buffer](#ipc_buffer) type
### SendIPCMessage(pid, [message](#ipc_msg))
Send message to process by pid
return [Error code](#ipc-error-codes)
### IPC Error codes
```lua
syscalls.IPCError.<Value>
```
+ `Ok`
+ `BufferLocked`
+ `BufferNotDefined`
+ `BufferOverflow`
+ `PIDNotExist`
### IPC_buffer
```lua
{
used: number,
lock: boolean,
Lock: (self: IPC_buffer) -> nil
Unlock: (self: IPC_buffer) -> nil
GetMessage: (self: IPC_buffer, i: number) -> IPC_msg
GetLastMessage: (self: IPC_buffer) -> IPC_msg
}
```
#### Lock(self)
Lock buffer
#### Unlock(self)
Unlock buffer
#### GetMessage(self, i)
return [message](#ipc_msg) that were send by number i
#### GetLastMessage(self)
return last sended [message](#ipc_msg)
### IPC_msg
```lua
{
pid: number,
size: number
}
```