Jump to content

calling resource


Dominate

Recommended Posts

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
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
  • Moderators

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 by DNL291
  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...