Dominate Posted April 15, 2018 Share Posted April 15, 2018 Hi guys, im asking if i can get name of resource that called a function from another resource. --- function from resource1 function Func() outputChatBox("That function called by: ".. resourceName) -- print 'That function called by: resource2' end --- resource2 exports["resource1"]:Func() Link to comment
SycroX Posted April 15, 2018 Share Posted April 15, 2018 3 minutes ago, Dominate said: Hi guys, im asking if i can get name of resource that called a function from another resource. --- function from resource1 function Func() outputChatBox("That function called by: ".. resourceName) -- print 'That function called by: resource2' end --- resource2 exports["resource1"]:Func() function testFunction(res) outputChatBox("this function called by : "..res, root, 255, 0, 0) end ------#from another resource exports["yourResource"]:testFunction(getResourceName(getThisResource())) you can try this for all your functions i think that there's no another way Link to comment
Dominate Posted April 15, 2018 Author Share Posted April 15, 2018 yeah i know that way but im asking is there's an easy way maybe there's a way by using debug library debug Link to comment
DNL291 Posted April 15, 2018 Share Posted April 15, 2018 (edited) debug.getinfo (https://www.lua.org/pil/23.1.html) An example: function a() local callingFunction = debug.getinfo(2) if callingFunction then print(callingFunction.name) end end function b() a() end b() EDIT After rereading your message, I realized that I answered it wrong since you meant the resource name and not the function name. So in this case, you can use the hidden variable "sourceResource", which represents the resource that called the exported function. --- function from resource1 function Func() local callingRes = sourceResource if callingRes then outputChatBox("That function called by: ".. getResourceName(callingRes)) -- print 'That function called by: resource2' end end Maybe this is only possible with the call function, I haven't tested it using exports. Edited April 16, 2018 by DNL291 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now