Skip to content
Screen edited this page Sep 5, 2026 · 20 revisions

Welcome to SL Wiki page!

Name

SL = Simple Language/Scripting Language/Simple scripting Language.
Call it whatever you want.

Variables

SL uses dynamic variables. For example:

# Correct way to define variable
var number = 10 # integer 
var string = "Hello, World" # string 
var char = 'A' # char 
var double = 10.1 # floating point
var bool = true # booleans
var long = 0xBFFF # or binary or octal, also used as pointer, but base language doesnt support pointers as well.
var number2 = 10 var number3 = 20 # number2 is 10 and number3 is 20

# Wrong way 
var number: int = 10 
int number = 20 
var number int = 20 
var number = 10, number2 = 40

Assignments

I dont support hidden assignments in SL, code should be clear enough on its own, and you should explicitly state what you re doing, which is why assignments aren't included in expressions.
For example:

# Correct way
var number = 10 
$number = 23

# Correct way 
var number2 = 20 
$number2 = 10 $number = 50 # now number2 is 10 and number is 50

# Wrong way 
10 + ($number = 32) - 20 

# Wrong way 
if ($number = 32) equ 32 then # ...

# Wrong Way 
function($number = 32, "Hello", false)

Conditions

In SL the only supported condition is the if block. For example:

# Condition expressions:
# equ = equal 
# neq = not equal
# eqg = equal or greater 
# eql = equal or lesser 
# > = greater 
# < = lesser 

# Correct way to use if
if (10 + 10) equ (20 + 10) - 10 then 
<CODE>
end

# Correct way to use if with else
if (10 + 10) equ (20 + 10) - 10 then 
<CODE>
else
<CODE>
end

if $number1 equ 20 then # ...
if function(10, 10) equ 20 then # ...
if 20 > function(10, 10) then # ...

# Correct way to use if with elif
if (10 + 10) equ (20 + 10) - 10 then 
<CODE>
elif (10 + 10) equ (20 - 10) + 10 then 
<CODE>
else
<CODE>
end

# Wrong way 
if (10 + 10) equ (20 + 10) - 10 then 
<CODE>
else if 
<CODE>
else 
<CODE>
end

Loops

SL only supports while loop. It works similarly to if. (Both continue and break are supported)
For Example:

var i = 0
while $i < 10 then 
   <CODE>
end

# Wrong way 
while $i < 10 { #...

TIP

Dont forget that while loops are very costly in SL, so heavy use of them can significantly reduce performance. Make sure to optimize your while loops as much as possible. Since SL doesnt use bytecode, while loops can be slower than in languages like Python, Lua, or Ruby, but with reasonable usage and proper optimization, their performance can sometimes be comparable.

Functions

SL uses a simple function syntax.
For example:

# Function without arguments
def func then 
<CODE>
end 

func()

# Function with arguments
def func -> number1, number2, string then 
    return $number1 + $number2 
end

func(10 + 10, 10 / 2)
func($number1 + 100 / (40 + 24), 10, "Hello, World") 

# Function with VA ARGS
def func -> number1, number2, ... then 
    # then arguments named like: <function_name>_VA_ARGUMENT_<index>
    return $number1 + $number2 + $func_VA_ARGUMENT_0 # which is first one
end

func(10, 10, 10)

# Wrong way 
def func() then #...
def func(number1, number2) then #...
def func -> number1 = 10, number2 = 20 then # ...

Expressions

SL supports all mathematical expressions and solves them at the speed of light.

Multiple Files

import file_name # without STRING LITERAL!! 

Extras

Here I'll provide information about the SL API so you can implement your own.

Standart Library

The project does not bundle stdlib.h together with the standard sl.c and sl.h single-header libraries included in the project directory.
If you want access to the standard library when using the scripting language, you will need to include your own implementation of stdlib.h in your project.
The required steps are described below:

// INCLUDE IT
#include "stdlib.h" // or your path

// Initialize it to load the standard library.
// This must be done after init_sl_process() and before calling
// open_sl_process() or sl_dostr_sl_process(), since the functions
// need to be loaded before the runtime starts.
init_sl_stdlib(&sl_code, argc, argv);

// When you are finished, shut it down to clean up the standard
// library and the memory allocations associated with it.
close_sl_stdlib();

Memory Allocation

In SL if you want to automatically allocate memory and continue on your way without having to deal with it yourself you first need to init a process.

// MAIN:
struct SL_Code  sl_code = sl_init_sl_process();

In the later steps I'll continue with the examples using the variable we allocated (sl_code).

Structure info

enum TokenTypes {
    T_UNKNOWN = 0,	
    T_IF, 
    T_DEF, 
    T_WHILE,
    T_THEN, 
    T_END, 
    T_VAR, 
    T_ELSE, 
    T_ELIF,
    T_IMPORT, 
    T_BREAK, 
    T_CONTINUE,
    T_RETURN,
    T_EQU,
    T_NEQ,
    T_EQG,
    T_EQL,
    T_AND,
    T_OR,
    T_SHLEFT,
    T_SHRIGHT,
};

struct SL_Code
{
    char **code;
    enum TokenTypes *types;
    int token_count;
    struct SL_Variable *vars;
    int total_size_v;
    int total_vars;
    struct SL_Function *funcs;
    int total_size_f;
    int total_funcs;
    int scope_depth;
};

Linking a Function

Linking functions in SL is very simple as shown below.

// YOUR FUNCTION
struct SL_Variable myfunc(struct SL_Code *code, struct SL_L_Function func, struct SL_Function rfunc) {
     // GETTING FUNCTION ARGUMENTS
     struct SL_Variable first_arg = sl_get_argument(*code, func, 0);
     // sl_get_argument(code from myfunc's arguments, func from myfunc's arguments, which argument? 0 is first, 1 is second, ...)
}

// MAIN:
sl_add_func(&sl_code, "myfunc", myfunc);

Adding a Raw Function

Raw functions are the standard way to add functions to SL. sl_add_raw_function gives you full control, but requires manual memory management, so use it carefully. Check sl.h for usage.

Getting Function info

If you want to get information about a function in SL you can use this function and store the function information in a variable of type SL_Function.

// MAIN:
struct SL_Function *getfu = sl_get_func(&sl_code, "print");
printf("Linked function? : %d\n", getfu->linked_function);

Copying a Function

If you want to copy information about a function in SL, you can use this function and store the result in a variable of type SL_Function.

// MAIN:
struct SL_Function copied = sl_copy_function(func);

Freeing a Function

If you want to free the memory used by a function in SL, you can use this function to free it.

sl_free_function(func <pointer>);

Structure info

struct SL_L_Function {
    int total_arguments;
    int *argument_indexes;
    int starting_index;
};

struct SL_Function
{
    char *name;
    unsigned long hash;
    struct SL_Variable *arguments;
    int total_arguments;
    char** code_tokens;
    enum TokenTypes *types;
    int code_len;
    int vaargs;
    struct SL_Variable (*funcr)(struct SL_Code*, struct SL_L_Function, struct SL_Function);
    int linked_function;
    int scope_lifetime;
};

Adding a Variable

Since adding a variable requires operations such as manually allocating memory, use the sl_dostr_sl_process function instead of the sl_add_var function (which hasn't even been tested).

// MAIN:
sl_dostr_sl_process(&sl_code, "var a = 10");

// FOR STRINGS
sl_dostr_sl_process(&sl_code, "var a = \"Hello, World\"");

Copying a Variable

If you want to copy information about a variable in SL, you can use this function and store the result in a variable of type SL_Variable.

// MAIN:
struct SL_Variable copied = sl_copy_variable(var);

Freeing a Variable

If you want to free the memory used by a variable in SL, you can use this function to free it.

sl_free_variable(var <pointer>);

Getting a Variable

If you want to get information about a variable in SL, you can use this function and store the result in a variable of type SL_Variable.

// MAIN:
struct SL_Variable *getva = sl_get_var(&sl_code, "enable_notify");
printf("Value of [%s]: %d\n", getva->name, getva->valb);

Pointer Type

Although pointer types aren't used in the base language, they are compatible with valh when used in functions linked from C.

Structure Info

enum SL_Types
{
    INIT = 0,
    INTEGER = 1,
    DOUBLE = 2,
    CHAR = 3,
    STRING = 4,
    BOOLEAN = 5,
    RETURN = 6,
    LONG = 7,
    ERROR = 8,
    POINTER = 9,
};

struct SL_Variable
{
    char *name;
    unsigned long hash;
    enum SL_Types type;
    int scope_lifetime;
    union
    {
        int vali;
        double valf;
        int valb;
        char valc;
        char *vals;
        long valh;
    };
};

Running a single String

As mentioned earlier you can use the sl_dostr_sl_process function to run strings that don't contain \n and aren't considered files.

// MAIN:
sl_dostr_sl_process(&sl_code, "print($a, \"\n\")");

Simple Helpers

To keep things short and easy to understand, I'll go over some basic helper functions here without getting into lengthy explanations.

// sl strings may be quoted, so use sl_string_getter to safely get the raw string without quotes.
char *raw_string = sl_string_getter(<VARIABLE OR QUOTED STRING> (For example: first_arg.vals));
// then free it when you finish your job
free(raw_string);

// you can use the c api to get the name of a variable that is being created or assigned a value at runtime.
char *assigned_val = sl_get_assignment_var();

// sl uses a scope system to track the scope depth of variables and functions, so you can get the current scope through the c api.
int scope_level = sl_get_scope(<CODE POINTER> (for example: &sl_code));
// note: scope 1 is the main code, scope 2 can be a function, scope 3 can be a scope inside that function, and so on. leaving a scope decreases the
// lifetime by 1, and it gets removed when it reaches 0. use -1 to make it persist across all scopes.

// variables and functions use simple hashes for faster lookup, then compare names for exact matches. use the hash string function.
unsigned long hash = sl_hash_string(<STRING> (for example: variable name/function name));

Opening a Process

You can automatically run files by opening an SL process.

// MAIN:
if (sl_open_sl_process(&sl_code, "file.sl") != 0) {
    exit(-1);
}
// sl_open_sl_process(SL_Code as pointer, filename)

Closing a Opened Process and Initialized Process

You can automatically close a process that has been opened or initialized.

// MAIN:
if (sl_close_sl_process(&sl_code) == -1) {
	fprintf(stderr, "close_sl_process failed.");
	return -1;
}

Example SL Code

import lib.sl

use("io")

var enable_notify = true
io.print("Hello world", "\n", 10, "\n", true, "\n", false, "\n", 10.1, "\n", 'A', "\n")
$enable_notify = false # setting false again
io.print("10 + 200 = ", add(10, 200), "\n")

For more complex examples, check the examples in the project tree.

Thats it!

Yes that's it! You've finished the entire wiki.

Clone this wiki locally