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

newlclosure

Overview of the newlclosure function.

Function definition
function newlclosure(closure: (...any) -> (...any)): (...any) -> (...any)

Remarks

This function will break if the environment of the emitted function is modified, do NOT call setfenvon the function that is returned, else it will not perform as expected.

High-Level Overview

Creates a Luau proxy that when called, will call closure with all the arguments provided to it.

Low-Level Overview

The function prepares two tables; as the function environment will be modified, the metatable contains an __index to another, it being the actual table we want to work on. In it we will push a global with an arbitrary name, after which we will compile Luau code that calls such a global. Then, when providing an env into luau_load we will provide the relative index of our environment table, after which the closure is returned.

When the function is called, it will first check its function environment for the function, and will later execute it. This is why calling setfenv on this function will destroy it, as no upreference or upvalue is used.

PreviousnewcclosureNextloadstring

Last updated 4 months ago