newcclosure
The newcclosure function will take the user’s inputted function and creates and returns a C closure that invokes the user’s original inputted function.
function newcclosure(func: (...any) -> (...any)): (...any) -> (...any)
local function test_func(arg: string): ()
print(arg);
return;
end;
return newcclosure(test_func)("Hello, world!");
This is useful when doing L-C hooking.
hookfunction
The hookfunction function will invoke the user’s hook when the target is called, and provide a clone of the target.
function hookfunction(target: (...any) -> (...any), hook: (...any) -> (...any), debug_name_str: string?): -> (...) ->(...any)
local hook: (...any) -> (...any); hook = hookfunction(warn, function(...: any): ...: any
print("warn was called");
return hook(...);
end);
print(hook == warn);
warn("Test");
This function is useful when wanting to block calls or modify return values from function calls
isnewcclosure
The isnewcclosure function will return a boolean indicating if the provided function was wrapped using newcclosure
function isnewcclosure(func: (...any) -> (...any)): boolean
print(isnewcclosure(print)); --> false
print(newcclosure(print)); --> true
This function is useful for determining fake C closures
clonefunction
The clonefunction function will clone the target func.
function clonefunction(func: (...any) -> (...any)): (...any) -> (...any);
local cloned_print = clonefunction(print);
print(cloned_print == print);
cloned_print("Hello, world!");
This function is useful when you do not want to call the target func
isexecutorclosure
The isexecutorclosure function will determine if the function’s source came from the executor
function isexecutorclosure(func: (...any) -> (...any)): boolean
print(isexecutorclosure(print)); --> false
print(isexecutorclosure(function() end)); --> true
print(isexecutorclosure(newcclosure(function() end))); --> false
print(isexecutorclosure(isexecutorclosure)); --> true
This function is useful if you need to identify where a specific function came from.
iscclosure
The iscclosure function will determine if the function is a C Closure
function iscclosure(func: (...any) -> (...any)): boolean
print(iscclosure(print)); --> true
print(iscclosure(function() end)); --> false
print(iscclosure(hookfunction)); --> true
print(iscclosure(function() end)); --> false
islclosure
The islclosure will determine if the function is a Lua Closure
function islclosure(func: (...any) -> (...any)): boolean
print(islclosure(print)); --> false
print(islclosure(function() end)); --> true
print(islclosure(newcclosure(function() end))); --> false
print(islclosure(hookfunction)); --> false;
The islclosure function will determine if the function is a Lua Closure
restorefunction
The restorefunction will unhook a function that has been hooked by hookfunction or hookmetamethod
function restorefunction(func: (...any) -> (...any)): ()
local function can_use()
return false;
end;
hookfunction(can_use, function()
return true;
end);
print(can_use()); --> true
restorefunction(can_use);
print(can_use()) --> false
This function is useful when you no longer need a function to be hooked.
isfunctionhooked
The isfunctionhooked function will determine if the function has been hooked by hookfunction or hookmetamethod
function isfunctionhooked(func: (...any) -> (...any)): boolean
print(isfunctionhooked(print)); --> false
hookfunction(print, function(...)
return warn(...);
end);
print(isfunctionhooked(print)); --> true
restorefunction(print);
print(isfunctionhooked(print)); --> false
This function is useful when you need to tell if a function is hooked.
setstackhidden
The setstackhidden will hide or unhide based on the hide parameter, the provided function or the provided level from the call-stack
function setstackhidden(func_or_lvl: (...any) -> (...any) | number, hide: boolean?): ()
setstackhidden(error, true);
-- now 'error' will be hidden from results like debug.info
xpcall(error, function(...)
print(debug.info(2, "f")); --> will not return `error`
end);
This function is useful when you need specific functions to be hidden from stack related functions, like debug.info and debug.traceback
__bytecode__
The __bytecode__ function will take in user provided bytecode and execute it.
function __bytecode__(bytecode_str: string) -> ()
__bytecode__(".global __main __main: GETIMPORT R0 1 [print] LOADK R1 K2 ['Hello, world!'] CALL R0 2 1 RETURN R0 1");
The bytecode is parased and executed as a new proto, keep in note a RETURN instruction is always required at the end of your bytecode.