File: _call_function

package info (click to toggle)
zsh-beta 4.3.2-dev-1%2B20061127-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 13,260 kB
  • ctags: 6,846
  • sloc: ansic: 83,534; sh: 5,094; makefile: 781; perl: 746; awk: 364; sed: 16
file content (32 lines) | stat: -rw-r--r-- 737 bytes parent folder | download | duplicates (18)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#autoload

# Utility function to call a function if it exists.
#
# Usage: _call_function <return> <name> [ <args> ... ]
#
# If a function named <name> is defined (or defined to be autoloaded),
# it is called. If <return> is given not the string `-' or empty, it is
# taken as the name of a parameter and the return status of the function
# called is stored in this parameter. All other arguments are given
# to the function called.
# The return value of this function is zero if the function was
# called and non-zero otherwise.

local _name _ret

[[ "$1" != (|-) ]] && _name="$1"

shift

if (( $+functions[$1] )); then
  "$@"
  _ret="$?"

  [[ -n "$_name" ]] && eval "${_name}=${_ret}"

  compstate[restore]=''

  return 0
fi

return 1