Finding your calling module
Wed Feb 22 19:02:55 CET 2006
Tom Whitcomb wrote:
>I'm using a callback pattern similar to the approach used in the gen_server. However, passing the module name around seems error prone and overly bound.
>Can a called function can determine the name of the module of its calling function without passing the module name as a parameter?
It depends on what you mean by "module of its calling function".
If you are using a pattern like gen_server and the call actually is a rpc
(a send between the caller and the callee) then I do not know how to do
it without explicitly passing the caller as an argument.
To find the closest caller on the callstack I have found the following hack
useful on occations.
(Note that tail-calls are not saved on the stack, and the solution is
quite hacky... erlang_fault is not guaranteed to give a good stacktrace...)
/Erik (Happi) Stenman
More information about the erlang-questions