Calling built-in functions indirectly. The dox say you can't do this
(see below), but I thought we discussed this some time back and found that
it was (in a very late breaking fix) actually implemented (fixed).
BEGIN { s = "sin";print @s(1) }
Still generates a fatal error.
(I found the text below via Google, but it looks like it is not in 4.1.1, which
is, I believe, still the latest released version)
--- Cut Here ---
Hello all.
I have just implemented improvements so that indirect calls work to both
built-in functions and to extension functions:
$ cat i.awk
BEGIN {
Quarter_pi = 3.1415927 / 4
print sin(Quarter_pi)
f = "sin"
print @f(Quarter_pi)
print substr("abcdefgh", 2, 3)
f = "substr"
print @f("abcdefgh", 2, 3)
}
$ ./gawk -f i.awk
0.707107
0.707107
bcd
bcd
And for extension functions:
$ cat j.awk
@load "filefuncs"
BEGIN {
ret1 = stat(".", data1)
print "ret1 =", ret1
f = "stat"
ret2 = @f(".", data2)
print "ret2 =", ret2
for (i in data1) {
if (! isarray(data1[i])) {
print i, data1[i]
if (! (i in data2) || data1[i] != data2[i]) {
printf("mismatch element \"%s\"\n", i)
}
}
}
}
$ export AWKLIBPATH=$PWD/extension/.libs
$ ./gawk -f j.awk
ret1 = 0
ret2 = 0
blksize 4096
devbsize 512
mtime 1409812755
mode 16877
type directory
dev 2053
gid 1000
ino 10364600
ctime 1409812755
blocks 8
nlink 18
name .
atime 1409812758
pmode drwxr-xr-x
size 4096
uid 1000
The documentation has been updated and the code will be in the git
repo shortly.
Arnold
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com
P.O. Box 354 Home Phone:
+972 8 979-0381
Nof Ayalon
D.N. Shimshon 9978500 ISRAEL
Vote Up! 0 Vote Down!
Report As Spam Reply arnold 9/4/2014
--- Cut Here ---