Giter Club home page Giter Club logo

z-sharp's Introduction

Z-Sharp is no longer in development! This project was never meant to go beyond the scope of a simple thing I could make pong in, yet people continue to ask for features and fixes, and I continue to oblige. So sadly, even though this was a cool project in which I learned a lot, it will be ending now. I will eventually make some docs and standards for the syntax, and will still leave this repository open. This way anybody can make their own interpreter or compiler for it. I will also still accept pull requests for any changes to this repository.

Introduction

Z-Sharp is a custom programming language I made because I don't like c++ very much (Z-Sharp's interpreter is written in c++ though). Z-Sharp scripts have the file extension .ZS. The base syntax and formatting I would say is quite similar to C# or Python, but differs as task complexity increases. It also has support for graphics using SDL2.

Before using Z#: There is no documentation, strings barely work, performance isn't great, the syntax is very specific, and most errors just cause it to crash without warning. I am just a single developer working on this during my free time; between school, other projects, and YouTube. Z-Sharp will most likely never be finished, since it was really supposed to end when the video was published about it. If you are trying to use a common programming language feature, ask yourself this: Is this feature required to play pong? If not, then most likely that feature has not been implemented yet. I initially only made the language so I could create pong and make a video about it, so it really is the bare minimum.

Documentation and getting started:

The docs and tutorial

Installation

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

Windows

  1. Navigate to the most recent release and download ZSharp-Win-Installer.zip.
  2. Unzip ZSharp-Win-Installer.zip and open the unzipped folder.
  3. Inside is a single file titled ZSharp-Setup.exe. Run it, and follow the setup instructions.
  4. If it fails to run, make sure the MS Visual Runtime and MSVC C++ Redistribute are installed. You can download them here from Microsoft
  5. Now that it is installed, there are a few ways to use it:
    • (recommended) Any ZSharp file that ends with .ZS will automatically be associated with the interpreter. Just double-click it, and the interpreter will run.
    • Drag and drop any .ZS script directly onto the executable.
    • Use command line, providing path to interpreter and then to script like so: > ./ZSharp.exe ./Pong-Example-Project/script.zs
  6. Feel free to use and edit the Pong-Example-Project. It is a single script called script.zs, and you can open it with any of the methods above. It is also located on the releases page.

If you don't want to install ZSharp on your device, or you want easier acces to the executable and .DLLs, another version is provided called ZS_Win_Base_Raw.zip. This just contains all of the files the installer puts on your computer.

Linux

  1. Install requirements: SDL2, SDL2 Image, SDL2 TTF Commands for apt and pacman below:

Debian

$ sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev

Arch

$ sudo pacman -S sdl2 sdl2_image sdl2_ttf
  1. Navigate to the most recent release and download ZSharp-Linux.zip.
  2. Unzip ZSharp-Linux.zip and open the unzipped folder.
  3. You will see some files. The Z# interpreter is ZSharp. Any time you want to execute a script, this is the program that will be used. You can use it like so:
    • Use terminal, providing path to executable and then to script like so: $ ./ZSharp ./Pong-Example-Project/script.zs
  4. Feel free to use and edit the included Pong-Example-Project. It is a single script called script.zs, and you can open it with any of the methods above.

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"
    {
        Printl(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)
{
    Printl("In A is: " + inputA)
    Printl("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, ZSharp 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.

z-sharp's People

Contributors

bsikar avatar jukeliv avatar kaputchino avatar rexo35 avatar sam-astro avatar theawesome98-real avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

z-sharp's Issues

Unable to run Main.cpp.

Can’t run Main.cpp, error. Shown:

image

I am running this on an iPad 10, please fix this bug.

Arrays and dictionaries

Is your feature request related to a problem? Please describe.
I am trying to make a 3D game using Z#, I want to create an array for the enemies, and a dictionary that stores the enemy's data

Describe the solution you'd like
I want to be able to make arrays and dictionaries.

Describe alternatives you've considered
Having a variable for everything, which was really just spaghetti code
(my code looked sort of like this)

global int enemies_1_health = 100;
global Sprite enemies_1_sprite = ZS.Graphics.Sprite("./enemy.png", NVec2(250, 250), NVec2(20, 20), 0);
global int enemies_1_movespeed = 1;

global int enemies_2_health = 100;
global Sprite enemies_2_sprite = ZS.Graphics.Sprite("./enemy.png", NVec2(250, 250), NVec2(20, 20), 0);
global int enemies_2_movespeed = 3;

and so on...

ZSharp segfaults if the font file that's loaded is missing

Describe your issue
If a font file is loaded that doesn't exist, rather than displaying an error message, the program segfaults
I'm using Ubuntu 20.04.4 LTS

To Reproduce
Steps to reproduce the behavior:

  1. change the arial.ttf in the pong program to something else but don't rename the font
  2. run the program
  3. watch it segfault

Add ZS.Math documentation

The docs are very minimal and are missing a lot of features. There should at least be a page to explain the various mathematical functions in ZSharp.

When following docs, window opens then immediately closes.

As I'm following the docs, the window immediately opens then closes when I run the basic hello world function. The code in my "hello.zs" file is:
func Main() {
Printl("Hello World!")
}

I then save the file and open it with ZSharp.exe, then the issue occurs.

macOS Not Supported

Describe your issue
So I built this program on macOS but it is not functional, I drag and drop the .zs file, which is Pong-Example-ZSharp And nothing happened

To Reproduce
Steps to reproduce the behavior:
You need to the brew package manager, copy this command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

If you already have the brew package manager

Copy this command:

brew install sdl2_image sdl2_ttf sdl2 git CMake ninja

After you did, clone this project:

git clone https://github.com/sam-astro/Z-Sharp/

Go to the directory:

cd /path/to/Z-Sharp/ZSharp

If you did that, Follow this command:

cmake -B build . -G "Ninja"

And then:

cd build && ninja

Now type ./ZSharp "executable file"

Docs

Will there be Docs or plan for Docs?

Simple movement not working?

Describe your issue
Okay so, I'm just starting out on Z#, so I decided to start making a game using it, but i'm getting an issue where the sprite doesn't move? Also, I can't add any empty new lines onto the update function? I get an error for doing that.

To Reproduce
Make a new file, add this onto it

int squareX = 250
int squareY = 250

func Main()
{
    int screenWidth = 500
    int screenHeight = 500

    ZS.Graphics.Init("Title of window", screenWidth, screenHeight)
}

func Start()
{
    Vec2 position = NVec2(squareX, squareY)
    Vec2 scale = NVec2(20, 20)
    float rotation = 0

    global Sprite exampleSprite = ZS.Graphics.Sprite("./square.jpg", position, scale, rotation)
}

func Update()
{
    ZS.Graphics.Draw(exampleSprite)
    if GetKey("W") == true
    {
        squareY -= 10
    }
    if GetKey("S") == true
    {
        squareY += 10
    }
    if GetKey("D") == true
    {
        squareX -= 10
    }
    if GetKey("A") == true
    {
        squareX += 10
    }
}

Could you create one with classes?

I found out that it is difficult to write a complex program: we need classes.
C++ is actually C with classes, so maybe you can update it and reneme to Z++
I suggest to use this syntax:

class ExampleClass (SuperClass)
{
    func constructor(Param1, Param2, ...)
    {
    // This function is called when the instantiated object is created
    // [some code]
    int this.example_attribute = 10
    super()    // call constructor function of super class
    this.super().ExampleMethod()    // call the static method 'ExampleMethod' of SuperClass
    this.ExampleMethod2()    // This is not defined in ExampleClass, so it will look for this function in SuperClass
    }

    func example_method(Param1, Param2, ...)
    {
    // [some code]
    }

    static int example_static_attr = 15
    // a static attribute/method is the attribute of class
    // e.g.
    // >> ExampleClass ExampleInstantiatedObj = (1, 2, 3)
    // >> printl(ExampleInstantiatedObj.example_static_attr)    => error
    // >> printl(ExampleClass.example_static_attr)                     => 15

    static func example_static_method(Param1, Param2, ...)
    {
    // [some code]
    }
}
ExampleClass a = (1, 2, 3)    // this calls a.contructor(1, 2, 3)
a.example_method()

P.S. This idea is mainly from javascript (constructor right?)
also it should support operator overloading then it looks much better

Cannot build on FreeBSD

Describe your issue

When building on FreeBSD, it says that SDL2_image is not found, though i have it installed

To Reproduce

On fbsd: git clone ...; cd Z-Sharp/ZSharp; cmake .

Screenshots
If applicable, add screenshots to help explain your problem.

Linux requirements missing

Describe your issue
Linux requirements for ZS are missing!

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'README.md'
  2. Look at requirements and find Linux.
  3. Where the requirements at???

Tutorial

Make an the tutorial, for this programming language because i'm really wan't learn this programming language or make docs for programming language how to code and etc.

Mac bianaries?

Will there ever be macOS binaries? Or maybe an installation tutorial for macOS would be another easier option.

Please fix your float to boost::any conversion errors that I had to patch manually

Describe your issue
The issue has to come down to how data types are handled in c++, for example you cannot assign floats to any. In this case
boost::any, this is the first issue with this code as it looks like it has not ben patched in the source.

To Reproduce
Steps to reproduce the behavior:

  1. Install all Libs for Z#
  2. Go to 'graphics.h'
  3. You see multiple errors in relation to any_cast and type assignments, most notably in:

boost::any SubComponent(std::string componentName) { if (componentName == "position") return position; if (componentName == "position.x") return position.x; if (componentName == "position.y") return position.y; if (componentName == "scale") return scale; if (componentName == "scale.x") return scale.x; if (componentName == "scale.y") return scale.y; return 0; }

Hope you fix this without other devs having to go line by line and fix the types, thanks in advance.
Screenshots
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.