From b9e7bb1b4b2b3b63de197cf9c752cfad8e3323af Mon Sep 17 00:00:00 2001 From: mfranz Date: Tue, 22 Jul 2008 19:03:25 +0000 Subject: [PATCH] add thisfunc() for reliable recursion --- Nasal/globals.nas | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Nasal/globals.nas b/Nasal/globals.nas index aacbdcc72..7dfe54ae5 100644 --- a/Nasal/globals.nas +++ b/Nasal/globals.nas @@ -99,6 +99,14 @@ var defined = func(sym) { } +## +# Returns reference to calling function. This allows a function to +# reliably call itself from a closure, rather than the global function +# with the same name. +# +var thisfunc = func caller(1)[1]; + + ## # Print log messages in appropriate --log-level. # Usage: printlog("warn", "..."); @@ -109,7 +117,7 @@ __ = {}; __.dbg_types = { none:0, bulk:1, debug:2, info:3, warn:4, alert:5 }; __.log_level = __.dbg_types[getprop("/sim/logging/priority")]; var printlog = func(level, args...) { - if(__.dbg_types[level] >= __.log_level) { call(print, args); } + if(__.dbg_types[level] >= __.log_level) call(print, args); }