Script APIs

Functions

loadstring

function loadstring(source: string, chunk_name?: string)

Equivalent to Lua 5.1's loadstring. This function may access the thread's global environment (getfenv(0)) to resolve/cache imports and builtins.

checkcaller

bool checkcaller()

Returns true if the current thread is owned by Synapse.

checkcallstack

bool checkcallstack(type: string, level?: int = 2)

Returns true if the current thread is owned by Synapse AND all functions at or above level in the call stack are Synapse functions. A level of 1 represents the function calling checkcallstack, 2 represents the function calling the function calling checkcallstack, and so forth.

issynapsefunction

bool issynapsefunction(f: function)

Returns true if f is a Synapse function.

islclosure

bool islclosure(f: function)

Returns true if f is a Lua function (as opposed to a C function).

decompile

string decompile(target: variant<function, LuaSourceContainer>, options?: table) [yields]

Decompiles target asynchronously. target cannot be a Synapse function. The following options can be used:

OptionDescriptionDefault
VerboseFunctionsAdds a comment to functions with their name and optionally other infotrue
FunctionLineAdds the line that a function is definedtrue
FunctionUpvaluesLists the upvalues of functionstrue
FunctionConstantsLists the constants that functions usefalse
RenameLoopVariablesGives for loop variables more specific names if possibletrue
VariableRenamingGives some variables contextual namestrue
ExtraRenamingRenames extra variablestrue
NullableNamingAllows variable renaming to ignore nil assignmentstrue
PrimitiveRenamingRenames variables with trivial primitive typestrue
SemicolonsAdds semicolons to the end of each statementtrue
TableNewlinesAdds a newline after each table entrytrue
UseIfElseExpressionAllows the use of if-else expressionfalse
CallLineInfoAdds a comment next to function calls of their linefalse
LazyFlatteningTry to less aggressively condense expressionstrue
FormatNamecallChainsAdds extra newlines in between chained namecallsfalse
FlattenGuardStatementsTurns guard statements into single linestrue
MaxCustomNameLengthMax length for variable names32
MaxTabsMax number of tabs20
MaxRationalDenominatorMax denominator for rationalization1000
DeduplicationThresholdThreshold for string deduplication10000

getscriptthread

thread getscriptthread(script: Instance)

Returns the main Lua thread associated with script. Note that this may not be the only thread used!

getsenv

table getsenv(script: Instance)

Returns the Lua environment (such as that returned by getfenv) associated with the main function of script. Essentially equivalent to getfenv(getscriptfunction(script)).

WARNING: Scripts may add a metatable to this value and check who's accessing it! If you want to get around this, check for whether the environment has a metatable and use syn.trampoline_call accordingly.

getscriptfunction

function getscriptfunction(script: Instance)

Returns the main function associated with script.

getscripthash

string getscripthash(script: LuaSourceContainer)

Returns a script's bytecode hash.

getfunctionhash

string getfunctionhash(script: function)

Returns a Lua function's bytecode hash.

getscriptname

string getscriptname(script: Instance)

Returns the name of a script when it was first loaded.

dumpbytecode

string dumpbytecode(target: variant<function, LuaSourceContainer>)

Dumps a function or script to the Luau bytecode format. target cannot be a Synapse function.

getcallingscript

variant<Instance, nil> getcallingscript()

Returns the script associated with the current thread or nil.

issynapsethread

bool issynapsethread(thread: thread)

Returns true if thread is owned by Synapse.

setsynapsethread

void setsynapsethread(set_to_synapse: bool, target_thread?: thread = nil)

Changes whether target_thread (or the current thread if target_thread is nil) can pass through checkcaller. If this is not the case, Synapse-specific overrides like game.HttpGet or Connection.Enabled will not work.