Built-in Functions
Usage:
print(...); -- ... :: str | any
print("hello, world!");
print("hello, ", "world!");
warn
Usage:
warn(...); -- ... :: str | any
warn("this is a warning!");
error
Usage:
error(msg: str, level: int)
error("error!");
error("error", 2);
len
Usage:
len(obj: array | str)
print(len("abc")) // 3
print(len([1, 2, 3])) // 3
ipairs
Usage:
ipairs(obj: array): dictionary(int, str)
let arr = [1, 2, 3];
let __iter = ipairs(arr);
for (k, v in __iter) {
print(k, v);
}
push
Usage:
push(array: array, value: any)
let arr = [6, 7, 4, 1];
push(arr, 3);
print(arr); // [6, 7, 4, 1, 3]
pop
Usage:
pop(array: array)
let arr = [1, 2, 3];
pop(arr);
print(arr); // [1, 2]
get
Usage:
get(array: array, index: int)
let arr = [1, 2, 3];
print(get(arr, 0)); // 1
remove
Usage:
remove(array: array, index: int)
let arr = [1, 2, 3];
remove(arr, 0);
print(arr); // [2, 3];
find
Usage:
find(array: array, value: any): int?
let arr = [1, 2, 3];
let idx = find(arr, 3);
print(arr);
format
Usage:
format(base_string: str, ... :: str): str
let username = "Jasper";
let welcome_message = format("Welcome, %s", username);
print(welcome_message); // Welcome, Jasper
printf
Usage:
printf(base_string: str, ... :: str)
let username = "Jasper";
printf("Welcome, %s", username); // Welcome, Jasper
str
Usage:
str(obj: any): str
let x = 10;
let s = str(x);
print(type(s)); // 'str'
print(s); // 10
int
Usage:
int(obj: any): int
let s = "10";
let i = int(s);
print(type(i)); // 'int'
print(i); // 10
hasattr
Usage:
hasattr(dict: dictionary, key: str): bool
let a = {
b: 5
}
print(hasattr(a, "b")); // true
getattr
Usage:
getattr(dict: dictionary, key: str): any
let a = {
b: 5
}
print(getattr(a, "b")); // 5
setattr
Usage:
setattr(dict: dictionary, key: str, value: any)
let a = {
x: 5
};
setattr(a, "y", 10);
print(a.y); // 10
loadmodule
Usage:
loadmodule(self, modulePath: str, ... :: any)
let task = loadmodule("@stdlib/task")!
task.wait(5);
//-------------------------------------//
let m = loadmodule("./Module")!
m.a();
//-------------------------------------//
let m = loadmodule("a.tfs")!;
m.a();
//-------------------------------------//
let m = loadmodule("a.luau")!;
//-------------------------------------//
let m = loadmodule("a.lua")!;
cloneobject
Usage:
cloneobject(obj: any): any
let s = "hi!";
let clone = cloneobject(s);
print(clone); // hi!
type
Usage:
type(obj: any): "fn" | "int" | "str" | "array" | "dictionary" | "bool"
let s = "hi";
print(type(s)); // str
getenv
Usage:
getenv()!: Dict(str, any)
let env = getenv()!; // will return a list of all 'let' variables and functions currently in the env.
for (key, val in env) {
print(key, val);
}
print(env);