Skip to content

afonsopereiraaa/Flex

Repository files navigation



Flex

A Flexible programming language

Key FeaturesHow To UseDownloadCreditsLicense

Key Features

  • Easy to learn and use
  • Easy to install
  • Flexible
  • Cross-Compatible "In the next days"

How To Use

Downloading or installing is very simple, here is how depending on your version and operating system:

Windows

Navigate to the most recent release and download Flex-Win-Installer.zip. Unzip Flex-Win-Installer.zip and open the unzipped folder. Inside is a single file titled Flex-Setup.exe. Run it, and follow the setup instructions. Now that it is installed, there are a few ways to use it: (recommended) Any Flex file that ends with .FX will automatically be associated with the interpreter. Just double-click it, and the interpreter will run. Drag and drop any .FX script directly onto the executable in your desktop. Use command line, providing path to interpreter and then to script like so: > ./Flex.exe example.fx

Linux

Coming in the next days ;)

Note If you can´t run the installer you can just download from the github.

Download

You can download the latest installable of Flex here

Here is some example code:

// Comments are indicated by two forward slashes
// They can only be on their own line
//    int j = 4 // <- This is invalid comment placement

// All programs start with a main function
func Main()
{
    int i = 0
    string s = "r"
    
    i += 2
    i -= 1
    i /= 3
    i *= 2
    
    while i < 10
    {
        i += 1
    }
    
    if s == "r"
    {
        print s + " is r"
    }
    
    int functionNumber = ExampleFunction("A", s)
    ExampleFunction(1, 3)
    
    GlobalFunction()
}

// Declare new function with 'func', then it's name, and the names of any input variables.
// The input variables don't need type, as those are automatic. Also, they don't need to
/// be assigned at all on execute and can be left blank
func ExampleFunction(inputA, inputB)
{
    print "In A is: " + inputA
    print "In B is: " + inputB
    
    // Return a value to the valling location
    return 4
}

func GlobalFunction()
{
    // Create variables that can be accessed from anywhere (ex. in Main or ExampleFunction) with the 'global' keyword before type
    global int x = 12
    global string y = "Y String"
}

Here is how to use graphics:

func Main()
{
    int screenWidth = 500
    int screenHeight = 500
    ZS.Graphics.Init("Title of window", screenWidth, screenHeight)
    // After graphics are initialized, the main function will not finish.
    // Instead, Start() will be called a single time, then Update() every frame after that.
}

// Runs once at start of graphics initialization
func Start()
{
    // Vec2 are initialized using function 'NVec2(x, y)'
    Vec2 position = NVec2(250, 250)
    Vec2 scale = NVec2(20, 20)
    float rotation = 0

    // Sprite object, stores (and loads from file) the texture, location, scale, and rotation
    global Sprite exampleSprite = ZS.Graphics.Sprite("./square.png", position, scale, rotation)
}

// Executes each frame
func Update(deltaTime)
{
    // Draws the image created in Start(). This is usually at the end of update.
    ZS.Graphics.Draw(exampleSprite)   
}

Currently, Flex is VERY strict with formatting, and can throw an error if you forget to put a space somewhere. Also, speaking of errors, if your code has any it will show in the console. Errors are colored red, and warnings are colored yellow. A line number will also usually be provided. This is Not the line relative to the documents beginning, but rather the functions beginning. Example:

ERROR: line 5 in function Main

This is the 5th line inside of Main.

func Main()
{
   // line 1
   // line 2
   // line 3
   // line 4
   int g = "s"
   // ^ above line is the error, since it is line 5
}

I am planning to change how error reporting works to report the document line number as well, but this is how it is for now.

I left a pong example game in the repository so you can check out :)

Credits

This software uses the following open source packages:

License

MIT


GitHub @flexplang  ·  Twitter @flexplang

About

The Flex Programming Language

Resources

License

Stars

Watchers

Forks

Packages

No packages published