getcallingscript
Returns the script that called the function you are in.
Syntax
getcallingscript() -> LuaSourceContainer?
Also available as
get_calling_script
Returns
| Type | Description |
|---|---|
LuaSourceContainer? | The script whose code called the current function, or nil. |
Description
It is most useful inside hooks: in a hookmetamethod or hookfunction hook it tells you which game script made the call. Frames from your own code and hidden frames are skipped, so the answer is the nearest game script below you. Called from your own top-level code it returns nil.
Example
local old
old = hookmetamethod(game, "__namecall", function(self, ...)
if not checkcaller() and getnamecallmethod() == "FireServer" then
local caller = getcallingscript()
print(caller and caller:GetFullName(), "fired", self.Name)
end
return old(self, ...)
end)
These are Game executor contracts. Check build requirements and session lifetimes before using them.
