>> What's your use case?
I have a bash script library that supports Objects and Classes in bash
script. I am now writing a loadable builtin to speed up the object call
and other mechanisms.
echo "'$obj'"
'_bgclassCall heap_A_XXXXX MyClass 0 |'
$obj.doSomething p1 p2
_bgclassCall is a function that sets up the method context (e.g. local
-n this=heap_A_XXXXX), and then calls the shell function that
corresponds to 'doSomething' (e.g. MyClass::soSomething)
_bgclassCall has a bash implementation but when the new builtin is
loaded I suppress the bash version so the builtin is used.
It also comes up for example if I want to implement the ConstructObject
function as a builtin, it identifies and runs the __constructor shell
functions while building up the object instance.
--BobG
P.S.
Here is a longer example of the syntax...
Example OO Bash...
$ cat /tmp/test.sh
#!/usr/bin/env bash
source /usr/lib/bg_core.sh
import bg_objects.sh ;$L1;$L2
DeclareClass Animal
function Animal::__construct() {
this[name]="${1:-anonymous}"
}
function Animal::speak() {
echo "${this[name]} says 'generic animal sound'"
}
DeclareClass Dog : Animal
function Dog::speak() {
echo "${this[name]} says 'woof'"
}
DeclareClass Cat : Animal
function Cat::speak() {
echo "${this[name]} says 'meow'"
}
declare -A spot; ConstructObject Dog spot "Spot"
declare -A whiskers; ConstructObject Cat whiskers "Whiskers"
$spot.speak
$whiskers.speak
$ bash /tmp/test.sh
Spot says 'woof'
Whiskers says 'meow'
On 5/2/22 15:31, Chet Ramey wrote:
On 5/2/22 3:23 PM, Robert E. Griffith wrote:
"execute_cmd.h" is not listed in the INSTALLED_HEADERS macro which
determines which headers are included for the install-headers target.
Yes, builtin commands are generally the target of execution, not things
that execute other builtins or shell functions. When builtins execute
other commands, it's either something like eval/command/source/exec or
the jobs -x/fc type of transform-and-execute.
Is it problematic for a loadable builtin to execute shell functions
or is it maybe an oversight that that header is not included? If I
build against the full source it appears to work fine but I wonder if
there are edge cases that cause problems.
It's not necessarily an oversight, just not something that builtin
commands
generally do. What's your use case?