HadesLang Doc
  • Overview
  • Getting Started
    • Installing Hades
    • Basic Syntax
    • Coding Conventions
  • Language Spec
    • Foundation
      • Types
      • Built-in functions
    • Operators
      • Comparison and equality
      • Logical operators
      • Bitwise operators
      • Compound Assignment Operators
      • Operator overloading
    • Control flow
      • Conditions
      • Loops
      • Exception handling
      • Ternary and nullcheck operators
      • Pipelines
    • Classes and variables
      • Declaring variables
      • Declaring classes
      • Declaring structs
      • Declaring protos
      • Declaring arrays
      • Type conversions in simple variable types
    • Actors
      • Message passing
      • GenServer
      • Channels
    • Functions and lambdas
      • Declaring functions
      • Declaring lambdas
    • Functions of simple types
      • int
      • string
      • float
      • bool
      • atom
      • pid
    • Other
      • Annotations
      • Comments
      • Preprocessor statements
      • Reflection
      • Script file arguments
      • this keyword
  • Core Libraries
    • Standard library
      • std:io
        • console
        • file
        • directory
      • std:exceptions
      • std:int
      • std:internals
        • annotations
          • findMethod
          • findMethodInProto
          • findMethods
          • findMethodsInProto
        • function
      • std:collections
        • map
        • list
      • std:math
        • math
        • constants
        • matrix
      • std:networking
      • std:os
      • std:params
      • std:string
      • std:sql
    • Extra libraries
      • mssql:client
  • Other
    • Tools
    • Examples
    • Todos
Powered by GitBook
On this page
  • set statement
  • if-else if-fi statement
  • import statement
  • function.hd
  • classDef.hd
  • main.hd
  • Result
  1. Language Spec
  2. Other

Preprocessor statements

set statement

The set statement, sets a preprocessor variable to a value. The values of preprocessor variables are not bound to types.

%set VERSION 0.7.1%
%set APPLICATION_NAME My Application%

Some variables are set by the Hades interpreter.

Variable

Content

OS

The operating system, a script is being ran on (can be: NT, Mac, Linux, Other)

OS_VERSION

The version of the operating system as int (417, 1803, 10136, etc...)

HADES_VERSION

The version of the Hades interpreter the script is being ran on as int

HAS_EVAL

1 if the Hades runtime has the eval function, 0 if not

HAS_INTERNALS

1 if the Hades runtime has the std:internals library, 0 if not

if-else if-fi statement

The if-elif-fi block has a couple special commands to compare values to each other.

Command

Full name

Returns true if

eq

Equals

Variables are equal

ne

Not equals

Variables are not equal

gt

Greater than

First variable is greater than second variable

lt

Lower than

First variable is lower than second variable

ge

Greater or equals

First variable is greater or equal to second variable

le

Lower or equals

First variable is lower or equal to second variable

with os from std:os
with console from std:io

var listCommand

%if eq OS Windows%
listCommand = "dir"
%else if eq OS Linux%
listCommand = "ls"
%else%
console.out("OS not recognized!")
os.exit(-1)
&fi%

%if ge OS_VERSION 1803%
os.exec("wslpath 'c:\users'")
%fi%

os.exec(listCommand)

import statement

The import statement copies the content of the specified file and pastes it into the source code (works recursively).

function.hd

func print(...a)
    for(var arg in a)
        console.out(arg)
    end
end

classDef.hd

class printer
%import function.hd%
end

main.hd

with console from std:io

%import classDef.hd%

printer().print("Hello","world")

Result

main.hd is being converted to:

with console from std:io

class printer
    func print(...a)
        for(var arg in a)
            console.out(arg)
        end
    end
end

printer().print("Hello","world")
PreviousCommentsNextReflection

Last updated 5 years ago