Class SystemBuiltinFunctions

java.lang.Object
org.daiitech.naftah.builtin.functions.SystemBuiltinFunctions

public final class SystemBuiltinFunctions extends Object

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 Details

    • SystemBuiltinFunctions

      private SystemBuiltinFunctions()
      Private constructor to prevent instantiation. Throws NaftahBugError if 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

      public static String getEnv(String variableName)
      Retrieves the value of an environment variable.

      This corresponds to System.getenv(String) and returns null if the variable is not defined.

      Parameters:
      variableName - the name of the environment variable
      Returns:
      the value of the environment variable, or null if not found
    • getEnv

      public static NaftahObject 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

      public static String getProperty(String key)
      Retrieves a system property by its key.

      Examples include:

      • os.name – operating system name
      • user.home – current user’s home directory
      • java.version – current Java version

      Parameters:
      key - the property key
      Returns:
      the property value, or null if undefined
    • getProperties

      public static NaftahObject getProperties()
      Retrieves all system properties as a map.

      This corresponds to System.getProperties() and returns a Properties object containing all system properties available to the JVM.

      Returns:
      a map of system property keys to their values
    • setProperty

      public static String setProperty(String key, String value)
      Sets a system property to the given key-value pair.
      Parameters:
      key - the property key
      value - the value to set
      Returns:
      the previous value of the property, or null if none
    • javaVersion

      public static String javaVersion()
      Returns the version of the currently running Java Runtime Environment.
      Returns:
      the Java version string (e.g., "17.0.2")
    • getVersion

      public static String getVersion()
      Returns the full current version of the Naftah, such as "1.2.3".
      Returns:
      the full Naftah version string
    • getShortVersion

      public static 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

      public static String osName()
      Returns the current operating system name.
      Returns:
      the OS name (e.g., "Windows 11", "Linux", "macOS")
    • userName

      public static String userName()
      Returns the name of the current user running the JVM.
      Returns:
      the system username
    • userHome

      public static String userHome()
      Returns the current user’s home directory path.
      Returns:
      the user home directory path