sunc docs
  • sUNC Introduction
  • Closures
    • hookfunction
    • hookmetamethod
    • newcclosure
    • iscclosure
    • islclosure
    • isexecutorclosure
    • clonefunction
    • getfunctionhash
  • Cryptography
    • crypt.base64encode
    • crypt.base64decode
  • Debug
    • debug.getconstants
    • debug.getconstant
    • debug.setconstant
    • debug.getupvalues
    • debug.getupvalue
    • debug.setupvalue
  • debug.getstack
  • debug.setstack
  • debug.getprotos
  • debug.getproto
  • Drawing
    • Drawing.new
      • Drawing Objects
    • cleardrawcache
    • getrenderproperty
    • setrenderproperty
    • isrenderobj
  • Environment
    • getgenv
    • getrenv
    • getgc
    • filtergc
  • Filesystem
    • appendfile
    • writefile
    • readfile
    • listfiles
    • isfile
    • delfile
    • loadfile
    • makefolder
    • isfolder
    • delfolder
    • getcustomasset
  • Instances
    • fireproximityprompt
    • fireclickdetector
    • firetouchinterest
    • getinstances
    • getnilinstances
    • cloneref
    • gethui
    • getcallbackvalue
    • compareinstances
  • Metatables
    • getrawmetatable
    • setrawmetatable
    • setreadonly
    • isreadonly
  • Miscellaneous
    • identifyexecutor
    • request
  • Reflection
    • gethiddenproperty
    • sethiddenproperty
    • setscriptable
    • checkcaller
    • setthreadidentity
    • getthreadidentity
  • Scripts
    • getscriptbytecode
    • getscripthash
    • getscriptclosure
    • getsenv
    • getscripts
    • getrunningscripts
    • getloadedmodules
    • getcallingscript
    • loadstring
  • Signals
    • getconnections
      • The Connection object
    • firesignal
    • replicatesignal
  • Websocket
    • WebSocket.connect
Powered by GitBook
On this page
  • Parameter
  • Example
  1. Closures

clonefunction

The cloned function must have the same environment as the original.

Any sort of modification to the original shouldn't affect the clone. Meaning that stuff like hooking the original will leave the clone unaffected.

Creates and returns a new function that has the same behaviour as the passed function.

function clonefunction<A..., R...>(function_to_clone: (A...) -> R...): (A...) -> R...

Parameter

  • func - The function to clone.


Example

local function DummyFunction()
    print("Hello")
end

local ClonedFunction = clonefunction(DummyFunction)

print(debug.info(ClonedFunction, "l")) -- Output: 1
print(debug.info(ClonedFunction, "n")) -- Output: DummyFunction
print(ClonedFunction == DummyFunction) -- Output: false
print(getfenv(ClonedFunction) == getfenv(DummyFunction)) -- Output: true
PreviousisexecutorclosureNextgetfunctionhash

Last updated 2 months ago