setthreadidentity
Sets the current thread's identity level.
Syntax
setthreadidentity(identity: number) -> voidParameters
| Parameter | Type | Description |
|---|---|---|
identity | number | The identity level (1-8) |
Returns
This function does not return a value.
Description
setthreadidentity changes the identity level of the current thread, which affects what APIs and properties are accessible.
Example
-- Check current identity
print("Before:", getthreadidentity())
-- Elevate identity
setthreadidentity(8)
print("After:", getthreadidentity())
-- Perform restricted operations hereSafe Identity Change
local function withIdentity(level, callback)
local original = getthreadidentity()
setthreadidentity(level)
local success, result = pcall(callback)
setthreadidentity(original)
if not success then
error(result)
end
return result
end
-- Use elevated identity temporarily
local result = withIdentity(8, function()
-- Restricted operations here
return "done"
end)Notes
- Higher identity gives more permissions
- Some operations require specific identity levels
- Always restore original identity when done
Related Functions
getthreadidentity- Get current identity
Aliases
setidentitysetthreadcontext