> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Closures

> Kiểm tra, tạo, sao chép và thay thế các bao đóng.

<div className="real-category-page">
  Kiểm tra, tạo, sao chép và thay thế các bao đóng.

  ## Hàm có sẵn

  <CardGroup cols={2}>
    <Card title="checkcaller" href="./checkcaller">
      Trả về liệu current Luau thread có nằm trong Real caller context hay không. Function không nhận arguments và push boolean result của the current caller context. Function không kiểm tra Lua call stack hoặc function object.
    </Card>

    <Card title="clonefunction" href="./clonefunction">
      Creates and returns a separate function value for the function passed as the first argument. The argument must be a function.
    </Card>

    <Card title="comparefunctions" href="./comparefunctions">
      So sánh hai function values bằng function identity của chúng. Cả hai arguments phải là functions. Function trả về boolean result của function identity(L, 1) == function identity(L, 2). Function không so sánh function bytecode, source, behavior, hashes, upvalues hoặc newcclosure mappings. comparefunction là alias cho cùng function.
    </Card>

    <Card title="getfunctionhash" href="./getfunctionhash">
      Returns an uppercase SHA384 hex digest derived from a Luau function. The argument must be a function, and C closures raise "Lua function expected". If no hashable function content is available, the function returns nil.
    </Card>

    <Card title="hookfunction" href="./hookfunction">
      Hook một target function bằng replacement function và trả về cloned copy của original target closure. Cả hai arguments phải là functions. Function trước tiên flush pending C function swaps, cloning target qua function cloning, thêm replacement closure hoặc mapped newcclosure target của nó vào hidden stack tracking, gọi FixCallstack cho target và cloned original, rồi patch target closure qua C closure, Luau closure hoặc newcclosure-specific path. Nếu target chưa có trong hook records, cloned original được lưu ở đó cho restorefunction. Returned function là cloned original closure.
    </Card>

    <Card title="hookmetamethod" href="./hookmetamethod">
      Tìm metamethod function trên một value và hook function đó thông qua hookfunction. First argument có thể là bất kỳ value nào được raw metafield lookup chấp nhận. Second argument phải là string metamethod name, và third argument phải là function replacement. Nếu raw metafield lookup không tìm thấy named metafield, function tạo "Metamethod doesn't exist" cho argument 2. Nếu metafield tồn tại nhưng không phải function, function tạo "Metamethod isn't a function" cho argument 2. Khi metafield là function, hookmetamethod gọi hookfunction với found metamethod function làm target và trả về cloned original closure của hookfunction.
    </Card>

    <Card title="iscclosure" href="./iscclosure">
      Returns whether the provided function is a C closure. The argument must be a function; passing any other type raises a type error. The function does not inspect executor ownership, source, bytecode, or upvalues.
    </Card>

    <Card title="isexecutorclosure" href="./isexecutorclosure">
      Returns whether the provided function is classified as executor-owned. The argument must be a function. The function does not inspect source text, debug names, bytecode hashes, or call stack ownership.
    </Card>

    <Card title="isfunctionhooked" href="./isfunctionhooked">
      Returns whether the provided function currently has a hook record. The argument must be a function.
    </Card>

    <Card title="ishiddenstack" href="./ishiddenstack">
      Returns whether a function, or the function at a stack level, is marked as hidden. target must be a function or stack level number. Invalid stack levels raise "Level out of range". isstackhidden is an alias.
    </Card>

    <Card title="islclosure" href="./islclosure">
      Returns whether the provided function is a Lua closure. The argument must be a function; passing a non-function raises a type error. isluaclosure is an alias.
    </Card>

    <Card title="isnewcclosure" href="./isnewcclosure">
      Returns whether the provided function is a newcclosure-created C closure. The first argument must be a function; passing a non-function raises a type error. Documented usage is a single function argument; extra arguments are not part of the supported signature.
    </Card>

    <Card title="newcclosure" href="./newcclosure">
      Returns a C closure for the provided function. If the function is already a C closure, the same function is returned. Passing a non-function raises a type error.
    </Card>

    <Card title="newlclosure" href="./newlclosure">
      Returns a Luau closure that calls the provided function. The first argument must be a function.
    </Card>

    <Card title="restorefunction" href="./restorefunction">
      Khôi phục hoặc thay thế function bằng cách gọi function hook operation bên trong và không trả về values. First argument phải là function. Với một function argument, function tìm the saved original function; nếu không có entry thì tạo "Function is not hooked". Sau đó gọi function hook operation với hooked closure và stored original closure, xóa Lua stack, và xóa restored closure khỏi hook records khi stored original đã được dùng. Nếu second argument cũng là function, function thay vào đó coi firstFunction là original function cần cài đặt và secondFunction là closure cần patch. O dang nay, khong thuc hien missing-original check voi gia tri hook records da luu; gia tri da luu chi duoc so sanh trong final remove check. Non-function second arguments bị branch condition bỏ qua. restorefunc và restoreclosure là aliases cho cùng function.
    </Card>

    <Card title="sethiddenstack" href="./sethiddenstack">
      Marks or unmarks a function, or the function at a stack level, as hidden. target must be a function or stack level number. hidden defaults to true. Invalid stack levels raise "Level out of range". setstackhidden is an alias.
    </Card>
  </CardGroup>
</div>
