Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yue

A small scripting language. I promise anything in ./src will never be more than 5k LoC okay.

Features

  1. Small
  2. Simple FFI API with C (no stack wrangling)
  3. Garbage Collected
  4. Slow but small
  5. Lack of Closure but small
  6. No Object Oriented Programming but again it's small
  7. Cute and Funny

Example

  1. Hello World
print("Hello, World")
  1. Variable
var a = 10;   // integer
var b = 20.5; // float
var c = "Hello, World"; // string
var d = [ a, b, c ]; // array
var e = { "name": "foo", "age": d[0] }; // table
print(e["name"])
  1. Branching
if(age < 10) {
    print("You are child")
} else if(10 <= age && age < 17) {
    print("You are teenage")
} else {
    print("You are adult")
}
  1. Loop
var i = 0;
while(i < 10) {
    i = i + 1;
}
  1. Function
fun main(args) {
    print("Hello, World")
    return 0;
}
  1. C FFI
#include "yue.h"
#include "raylib.h"
#include <string.h>
#include <assert.h>

...

yue_value f_init_window(yue_context *ctx, yue_value *args, int argc)
{
    if(argc < 3) yue_errorf(ctx, "this function requires more than 3 arguments got %d", argc);
    int width  = yue_toint(ctx, args[0]);
    int height = yue_toint(ctx, args[1]);
    const char * title = yue_tocstr(ctx, args[2]);
    InitWindow(width, height, title);
    return yue_nil(ctx, 0);
}

int main(int argc, char *argv[]) {
    Yue_Context *ctx = yue_open();

    assert(argc > 0)
    char *source = read_entire_file_text(argv[1]);
    if(!source) return -1;

    yue_set_global_value(ctx, "init_window", yue_cfunc(f_init_window));

    int ret = yue_do_string(ctx, argv[1], source, strlen(source));
    yue_close(ctx);

    return ret;
}

Releases

Packages

Contributors

Languages