diff --git a/hawk/lib/mod-hawk.c b/hawk/lib/mod-hawk.c index f1cddf21..6a2fa3b0 100644 --- a/hawk/lib/mod-hawk.c +++ b/hawk/lib/mod-hawk.c @@ -112,6 +112,30 @@ static int fnc_call (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) return 0; } +/* hawk::function_exists("xxxx"); */ +static int fnc_function_exists (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) +{ + hawk_val_t* a0; + hawk_ooch_t* str; + hawk_oow_t len; + int rx; + + a0 = hawk_rtx_getarg(rtx, 0); + str = hawk_rtx_getvaloocstr(rtx, a0, &len); + if (HAWK_UNLIKELY(!str)) + { + rx = 0; + } + else + { + rx = (hawk_rtx_findfunwithoocstr(rtx, str) != HAWK_NULL); + hawk_rtx_freevaloocstr (rtx, a0, str); + } + + hawk_rtx_setretval (rtx, hawk_rtx_makeintval(rtx, rx)); + return 0; +} + /* hawk::gc(); hawk::gc_get_threshold(gen) @@ -193,6 +217,7 @@ static fnctab_t fnctab[] = { /* keep this table sorted for binary search in query(). */ { HAWK_T("call"), { { 1, A_MAX, HAWK_T("vR") }, fnc_call, 0 } }, + { HAWK_T("function_exists"), { { 1, 1, HAWK_NULL }, fnc_function_exists, 0 } }, { HAWK_T("gc"), { { 0, 1, HAWK_NULL }, fnc_gc, 0 } }, { HAWK_T("gc_get_threshold"), { { 1, 1, HAWK_NULL }, fnc_gc_get_threshold, 0 } }, { HAWK_T("gc_set_threshold"), { { 2, 2, HAWK_NULL }, fnc_gc_set_threshold, 0 } }