Class SystemBuiltinFunctions
System Built-in Functions
This class provides a set of built-in functions derived from the Java System class.
These functions expose system-level features such as environment access, system properties,
current time retrieval, and runtime information to the Naftah scripting environment.
All functions are registered under the Arabic names provided in their NaftahFn annotations.
Example usage:
الوقت_الحالي_بالملي()
اقرأ_متغير_بيئة("JAVA_HOME")
اقرأ_خاصية("os.name")
اسم_النظام()
- Author:
- Chakib Daii
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic longReturns the current time in milliseconds since the Unix epoch (January 1, 1970 UTC).static NaftahObjectgetEnv()Retrieves all environment variables as a map.static StringRetrieves the value of an environment variable.static NaftahObjectRetrieves all system properties as a map.static StringgetProperty(String key) Retrieves a system property by its key.static StringReturns the short Naftah version string, containing only the major and minor parts.static StringReturns the full current version of the Naftah, such as "1.2.3".static StringReturns the version of the currently running Java Runtime Environment.static longnanoTime()Returns the current value of the JVM's high-resolution time source, in nanoseconds.static StringosName()Returns the current operating system name.static StringsetProperty(String key, String value) Sets a system property to the given key-value pair.static StringuserHome()Returns the current user’s home directory path.static StringuserName()Returns the name of the current user running the JVM.
-
Constructor Details
-
SystemBuiltinFunctions
private SystemBuiltinFunctions()Private constructor to prevent instantiation. ThrowsNaftahBugErrorif called.
-
-
Method Details
-
currentTimeMillis
public static long currentTimeMillis()Returns the current time in milliseconds since the Unix epoch (January 1, 1970 UTC).This function is equivalent to
System.currentTimeMillis()and is often used for measuring time intervals or timestamps.- Returns:
- the current system time in milliseconds
-
nanoTime
public static long nanoTime()Returns the current value of the JVM's high-resolution time source, in nanoseconds.This value is only meaningful when comparing two calls to measure elapsed time, not as an absolute timestamp.
- Returns:
- the current high-resolution time in nanoseconds
-
getEnv
Retrieves the value of an environment variable.This corresponds to
System.getenv(String)and returnsnullif the variable is not defined.- Parameters:
variableName- the name of the environment variable- Returns:
- the value of the environment variable, or
nullif not found
-
getEnv
Retrieves all environment variables as a map.This corresponds to
System.getenv()and returns an unmodifiable map containing all environment variables available to the JVM.- Returns:
- a map of environment variable names to their values
-
getProperty
Retrieves a system property by its key.Examples include:
os.name– operating system nameuser.home– current user’s home directoryjava.version– current Java version
- Parameters:
key- the property key- Returns:
- the property value, or
nullif undefined
-
getProperties
Retrieves all system properties as a map.This corresponds to
System.getProperties()and returns aPropertiesobject containing all system properties available to the JVM.- Returns:
- a map of system property keys to their values
-
setProperty
Sets a system property to the given key-value pair.- Parameters:
key- the property keyvalue- the value to set- Returns:
- the previous value of the property, or
nullif none
-
javaVersion
Returns the version of the currently running Java Runtime Environment.- Returns:
- the Java version string (e.g., "17.0.2")
-
getVersion
Returns the full current version of the Naftah, such as "1.2.3".- Returns:
- the full Naftah version string
-
getShortVersion
Returns the short Naftah version string, containing only the major and minor parts.Example: "1.2" for version "1.2.3". Throws an exception if the format is invalid.
- Returns:
- the short Naftah version
-
osName
Returns the current operating system name.- Returns:
- the OS name (e.g., "Windows 11", "Linux", "macOS")
-
userName
Returns the name of the current user running the JVM.- Returns:
- the system username
-
userHome
Returns the current user’s home directory path.- Returns:
- the user home directory path
-