Environment
Filesystem
All files in your repository with a known extension will be exposed via a virtual filesystem.
.lua
files can be loaded using the standard libraryrequire()
..toml
files can be loaded using the functionFile.LoadTOML
..json
files can be loaded using the functionFile.LoadJSON
or in the case of behavior treesBT.Load
..wav
files can be loaded using the functionFile.LoadAudio
..png
,.gif
,.bmp
and.jpg
files can be loaded using the functionFile.LoadSprites/File.LoadTexture
..obj
files can be loaded using the functionFile.LoadModel
..mtl
files can be bundled together with the.obj
files although they can't be directly accessed.
With all of these primitives, path string is case insensitive and you may omit the extension with the exception of LoadSprites/LoadTexture
. The path is relative to the module base by default but you can prefix it with @
to signify global lookup which ignores the current path allowing you to read other modules files.
You may choose to prevent any files from being shared by using _
either in the directory or the file name as a prefix (e.g. /_private/x.png
or /resources/_private.png
), however do note that Lua files are already unreadable so there's no real reason to do so unless you're trying to keep a data file or art that belongs to you private.
-- Returns all directory and files at the given directory path, entries that are directories are terminated with '/'.
string[] File.Enumerate(string path, int? level)
-- Checks the existance of a file at the given path.
bool File.Exists(string path, int? level)
-- Loads a JSON file and returns it as a Lua object.
any File.LoadJSON(string path, int? level)
-- Loads a TOML file and returns it as a Lua object.
any File.LoadTOML(string path, int? level)
-- Loads the given texture as a sprite map and returns the texture id and the width and height of the atlas.
{int, int, int} File.LoadSprites(string path, int? dims, int? level)
-- Loads the given texture as a singular sprite
{int, float} File.LoadTexture(string path, int? flags, int? level)
-- Loads an audio file and returns the audio bank id.
int File.LoadAudio(string path, int? level)
-- Loads the Wavefront object as a CommandBuffer.
CommandBuffer File.LoadModel(string path, int? level)
-- Gets the current path.
string File.CurrentPath(int? level)
Example
local a = require "directory.test"
local b = require "directory/test"
local j = File.LoadJSON("directory/test")
local t = File.LoadTOML("directory/test")
print(a, b, j.a, j.b, t.a.b) -- Prints "42 42 42.4 42.42 42.4242"
return 42
{ "a": "42.4", "b": 42.42 }
[a]
b = 42.4242
For the security of your private scripts, we have disabled string.dump
globally, and additionally you cannot read any .lua
file using these primitives.
Dependencies
We consider every public directory with a index.lua
or index.ts
an exported module. Exported modules can only be accessed after the Init
event and they will need to be referenced. Every other script is lazily loaded and you can use the require
function to import them.
An exception to this is the core modules provided by us, all of which you can access by their name as if they were builtins (e.g. Core/Aimbot
-> Aimbot.*
) and are guaranteed to be loaded before any other scripts thus eliminating the need to wait for the Init
event.
-- Initialization event that gets emitted after module parsing is complete.
-- Note: `Init` event cannot be used after it is triggered.
Event<void> Event.OnInit
Exports
- SR Lua
- TypeScript
Every non-local variable and function in the index.lua
file will be a public export. For all other scripts, you must return the export list explicitly.
Value = 5
Value = 6
return { Value = 7 }
Both modules and scripts follow typescript syntax.
export const Value = 5;
export const Value = 6;
export const Value = 7;
Imports
- SR Lua
- TypeScript
Module entries are accessed using the global @<ModuleName>
tables or by calling the function @
with the module name. Alternatively if this is an essential import you can use require function with the argument @<ModuleName>
/@<ModuleName>.index
.
local test = require "@ModA.test"
print(test.Value) -- 7
Event.OnInit |_| do
print(@ModA.Value) -- 5
print(@[[ModA.B]].Value) -- 6
end
Modules can be imported by simply declaring an ambient module with the exact name. Scripts on the other hand require invocation of the Require
helper or ambient declarations in the @<ModuleName>
directory in the project root.
declare const Value: number;
declare const Value: number;
declare const Value: number;
import { Value as V0 } from "@ModA";
import { Value as V1 } from "@ModA/B";
import { Value as V2 } from "@ModA/test";
print(V0, V1, V2); // 5, 6, 7