RbxStu V3 Docs
  • Welcome
  • Information
    • Engine Information
      • Luau API Security
  • Stunc
    • Overview
    • Connections
    • Filesystem
      • readfile
      • writefile
      • appendfile
      • isfile
      • isfolder
      • listfiles
      • makefolder
      • delfile
      • delfolder
      • loadfile
      • dofile
  • Memory
    • getgc
    • reference_object
    • unreference_object
    • get_gc_threshold
  • Closures
    • isunhookable
    • makeunhookable
    • ishooked
    • restorefunction
    • hookfunction
    • hookmetamethod
    • isourclosure
    • iscclosure
    • islclosure
    • clonefunction
    • newcclosure
    • newlclosure
    • loadstring
Powered by GitBook
On this page
  1. Closures

loadstring

Overview of the loadstring function.

Function definition
function loadstring(source: string, chunkName: string?): ((...any) -> (...any) | nil, string?)

Remarks

If no chunkName is provided, =loadstringwill be used in its place.

The proto inherits the capabilities from its latest caller in Luau context.

sourceis compiled with optimisation level 1 and debugging level 2.

This function as a side effect, will disable environment optimisations by declaring the current thread's environment to be unsafe; this means that code may execute slower in Luau due to some optimisations of the LVM not being available anymore.

High-Level Overview

Compiles the provided source into a Luau closure that can be run.

Low-Level Overview

The source and chunkName are obtained from the Luau stack and are compiled utilising theLuau::Compile function after source is compiled into Luau Bytecode; it is then loaded utilising luau_load, with the environment being the global environment. Should compilation or loading the closure fail, the first return will be nil, whilst the second will be the error. Should it succeed, it will return the closure as its first return.

Previousnewlclosure

Last updated 4 months ago