* Hooking up to function definition via module
@ 2017-04-18 8:23 Sebastian Gniazdowski
2017-04-19 20:57 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Gniazdowski @ 2017-04-18 8:23 UTC (permalink / raw)
To: zsh-users
Hello,
I would like to receive a callback or something else, when a function is defined. For example, I can detect setopt by wrapping bin_setopt(), like this:
Builtin bn = (Builtin) builtintab->getnode2(builtintab, "setopt");
bn->handlerfunc = bin_setopt2;
So in theory I can analyze setopt arguments in bin_setopt2(), record which option is being set, even if it is already set to requested state, then call original bin_setopt().
I think I cannot do something similar with function redefinition/definition, because there isn't a builtin dedicated to this, so I cannot wrap that builtin. But maybe I'm wrong?
--
Sebastian Gniazdowski
psprint /at/ zdharma.org
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Hooking up to function definition via module
2017-04-18 8:23 Hooking up to function definition via module Sebastian Gniazdowski
@ 2017-04-19 20:57 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2017-04-19 20:57 UTC (permalink / raw)
To: zsh-users
On Apr 18, 10:23am, Sebastian Gniazdowski wrote:
}
} So in theory I can analyze setopt arguments in bin_setopt2(), record
} which option is being set, even if it is already set to requested
} state, then call original bin_setopt().
Yes, but -- options can also be changed as a consequence of "emulate",
even long after the the emulate command has come and gone, because of
"sticky emulation" (emulate zsh -c 'myfunc() ...'); and there is a
moderate list of options that either can't be changed by setopt, or
that can't be unwound by localoptions.
} I think I cannot do something similar with function
} redefinition/definition, because there isn't a builtin dedicated to
} this, so I cannot wrap that builtin. But maybe I'm wrong?
You are correct -- function definitions are handled entirely by the
parser, there is no table-driven lookup that you can subvert.
Depending upon exactly what your goal is -- I'm guessing it's to make
a module for your plugin manager -- you might be able to do a lot of
the work with a function call wrapper. See zprof.c for an example.
This is getting into zsh-workers territory rather than -users.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-04-19 20:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-18 8:23 Hooking up to function definition via module Sebastian Gniazdowski
2017-04-19 20:57 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).