How Do I Get A Pointer To A Built In ColdFusion Method?

Does anyone know how to get a pointer to a built in ColdFusion method? I want to do something along the lines of:

<!--- Check for regular expression search. --->

<cfif ARGUMENTS.IsRegex>

<!--- Get regex find. --->

<cfset Method = REFindNoCase />

<cfelse>

<!--- Get standard find. --->

<cfset Method = FindNoCase />

</cfif>

<!--- Use method pointer. --->

<cfif Method( "foo", "I like foo bar" )>

<!--- Code here. --->

</cfif>

The problem with this is that it throws an undefined variable error (FindNoCase). Now, I know the idea is sound as I have done it with user defined methods. But those methods are all scopes in some way and are very easy to reference. Built in ColdFusion methods are proving quite hard to find!

My java knowledge is almost non-existent. This may not help at all, but I figure it never hurts to share information.

I found a post about running your own Java libraries with coldfusion. In one of the comments, Mark mentions that his code supports access to built in classes and libraries, although I didn't see an example of that.

Look at the example I gave. It checks a flag for regular expression usage and then uses either a REFind() or Find() method. This is actually the situation where this came up. REFind() and Find() have the same arguments, it should be very easy to swap them out.

Now, imagine if that was part of some HUGE CFIF statement. I wouldn't want to duplicate the logic depending on a flag.

I guess it's just a matter of opinion. Your solution, which is good, requires another UDF to be defined. Nothing wrong with that. But I just feel for something that should be really simple, having a proxy method ties the given UDF to more parts of an application that it needs to be.

David,In that situation, I don't think there is much difference between

if (condition)return somethingelsereturn something else

In fact, a lot of people are big fans of having a single point of return in a function, as it can make it easier to follow knowing there is only one place the function returns control to its calling code.

With all that said though, I think I'd simply use the REFind if there was a chance of using regular expressions. After all, it's still a regular expression even if you don't use any special characters.

The problem with always using REFind() is that the string you are searching for might have "reg-ex" specific characters, so unless you want to escape all characters in the reg-ex substring, then no go.

Thanks for the suggestion. I talked to Michael Dinowitz yesterday at CFUNITED Express NYC and he said that this cannot be done (getting method pointers) for built in methods because the methods (as opposed to UDFs) are just wrappers for the Java methods. They are not really first class objects like UDFs.

Oh, I see. Yeah, those are some tricky methods. I think that is part of what the JavaProxy thing does - it figures out how to invoke those between CF and Java. I have heard that no one can figure out how to call the Invoke methods directly.

I believe that they can yes, the classes are different.coldfusion.runtime.CfJspPage._invoke(...)coldfusion.runtime.TemplateProxyFactory.resolveName()http://www.mxstudio.com.br/views.tutorial.php?act=view&cid=7&aid=699