The sys
namespace provides essential system operations including I/O, time, process control, and foreign function interface capabilities.
sys::Print(msg: String): Void
- Prints a string to standard outputsys::PrintLine(msg: String): Void
- Prints a string followed by a newlinesys::ReadLine(): String?
- Reads a line from standard input, returns null
on EOFsys::ReadChar(): Char?
- Reads a single character from standard input, returns null
on EOFsys::UnixTime(): Int
- Returns current Unix timestamp (seconds since epoch)sys::UnixTimeMs(): Int
- Returns current Unix timestamp in millisecondssys::UnixTimeNs(): Int
- Returns current Unix timestamp in nanosecondssys::NanoTime(): Int
- Returns high-resolution monotonic time in nanosecondssys::FormatDateTime(timestamp: Int, format: String): String?
- Formats Unix timestamp using format stringsys::FormatDateTimeMs(timestampMs: Int, format: String): String?
- Formats millisecond timestampsys::ParseDateTime(dateString: String, format: String): Int?
- Parses date string to Unix timestamp%Y
- 4-digit year (e.g., 2024)%m
- Month (01-12)%d
- Day of month (01-31)%H
- Hour (00-23)%M
- Minute (00-59)%S
- Second (00-59)%s
- Unix timestamp%f
- Microseconds (000000-999999)%n
- Nanoseconds (000000000-999999999)sys::OpenFile(path: String, mode: FileMode): File?
- Opens a file with specified modesys::OpenFile(path: String, mode: FileMode, permissions: Int): File?
- Opens file with custom permissionssys::FileMode::Read
- Open for reading onlysys::FileMode::Write
- Open for writing only (truncates existing file)sys::FileMode::Append
- Open for writing, append to endsys::FileMode::ReadWrite
- Open for both reading and writingsys::FileMode::Create
- Create new file, fail if existssys::FileMode::CreateNew
- Create new file, fail if existssys::FileMode::Truncate
- Open and truncate to zero lengthsys::FileExists(path: String): Bool
- Checks if file existssys::DirectoryExists(path: String): Bool
- Checks if directory existssys::CreateDirectory(path: String): Bool
- Creates directory, returns false
on errorsys::DeleteFile(path: String): Bool
- Deletes file, returns false
on errorsys::DeleteDirectory(path: String): Bool
- Deletes empty directory, returns false
on errorsys::MoveFile(source: String, destination: String): Bool
- Moves/renames filesys::CopyFile(source: String, destination: String): Bool
- Copies filesys::GetFileSize(path: String): Int?
- Returns file size in bytes, or null
on errorsys::GetFileModifiedTime(path: String): Int?
- Returns file modification time as Unix timestampsys::ListDirectory(path: String): StringArray?
- Lists directory contents, returns null
on errorsys::GetCurrentDirectory(): String?
- Returns current working directorysys::ChangeDirectory(path: String): Bool
- Changes current directory, returns false
on errorsys::GetAbsolutePath(path: String): String?
- Returns absolute path, or null
on errorsys::Sleep(ms: Int): Void
- Sleeps for specified millisecondssys::SleepNs(ns: Int): Void
- Sleeps for specified nanosecondssys::Exit(code: Int): Never
- Terminates the process with exit codesys::GetProcessId(): Int
- Returns current process IDsys::GetEnvironmentVariable(name: String): String?
- Gets environment variable valuesys::SetEnvironmentVariable(name: String, value: String): Bool
- Sets environment variablesys::Random(): Int
- Returns random 64-bit integersys::RandomRange(min: Int, max: Int): Int
- Returns random integer in range [min, max)sys::RandomFloat(): Float
- Returns random float in range [0.0, 1.0)sys::RandomFloatRange(min: Float, max: Float): Float
- Returns random float in range [min, max)sys::SeedRandom(seed: Int): Void
- Seeds the random number generatorsys::GetMemoryUsage(): Int
- Returns current memory usage in bytessys::GetPeakMemoryUsage(): Int
- Returns peak memory usage in bytessys::ForceGarbageCollection(): Void
- Forces garbage collectionsys::GetProcessorCount(): Int
- Returns number of available CPU coressys::ResolveHostname(hostname: String): String?
- Resolves hostname to IP addresssys::IsPortOpen(host: String, port: Int): Bool
- Checks if TCP port is opensys::GetLocalIpAddress(): String?
- Returns local machine’s IP addresssys::GetOsName(): String
- Returns operating system namesys::GetOsVersion(): String
- Returns operating system versionsys::GetArchitecture(): String
- Returns CPU architecture (e.g., “x64”, “arm64”)sys::GetUserName(): String?
- Returns current usernamesys::GetHomeDirectory(): String?
- Returns user’s home directorysys::GetLastError(): String?
- Returns description of last system errorsys::ClearError(): Void
- Clears the last error statesys::Interope(dllName: String, functionName: String, input: ByteArray, output: ByteArray): Int
unsafe
.input
contains parameters to pass to the functionoutput
buffer receives the function’s return value// Get current time in different formats
val unixTime: Int = sys::UnixTime()
val unixTimeMs: Int = sys::UnixTimeMs()
val unixTimeNs: Int = sys::UnixTimeNs()
// Format current time
val formatted: String? = sys::FormatDateTime(unixTime, "%Y-%m-%d %H:%M:%S")
if (formatted != null) {
sys::PrintLine("Current time: " + formatted)
}
// High-precision timing
val start: Int = sys::NanoTime()
// ... do some work ...
val end: Int = sys::NanoTime()
val duration: Int = end - start
sys::PrintLine("Operation took " + duration.ToString() + " nanoseconds")
// Read and write files
val file: File? = sys::OpenFile("data.txt", sys::FileMode::Read)
if (file != null) {
val content: String? = file.ReadAllText()
if (content != null) {
sys::PrintLine("File content: " + content)
}
file.Close()
}
// Write to file
val outputFile: File? = sys::OpenFile("output.txt", sys::FileMode::Write)
if (outputFile != null) {
val success: Bool = outputFile.WriteAllText("Hello, World!")
if (success) {
sys::PrintLine("File written successfully")
}
outputFile.Close()
}
// Directory operations
if (sys::CreateDirectory("new_folder")) {
sys::PrintLine("Directory created")
}
val files: StringArray? = sys::ListDirectory(".")
if (files != null) {
for (filename in files) {
sys::PrintLine("File: " + filename)
}
}
// Get system information
sys::PrintLine("OS: " + sys::GetOsName() + " " + sys::GetOsVersion())
sys::PrintLine("Architecture: " + sys::GetArchitecture())
sys::PrintLine("CPU cores: " + sys::GetProcessorCount().ToString())
sys::PrintLine("Memory usage: " + sys::GetMemoryUsage().ToString() + " bytes")
// Environment variables
val path: String? = sys::GetEnvironmentVariable("PATH")
if (path != null) {
sys::PrintLine("PATH: " + path)
}
Note: All function names use PascalCase (e.g.,
UnixTime
,OpenFile
). The namespace remainssys
.