Re: Q: A way to determine if function is defined

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Q: A way to determine if function is defined

Luiz Henrique de Figueiredo
>From [hidden email]  Tue Mar 14 08:39:35 2000
>From: "Maciej Maczynski" <[hidden email]>
>
>Is there a method in Lua to check from within a script if the function is
>defined?

To check whether f(x,y,z,...) is ok, just do
	if type(f)=="function" then f(x,y,z,...) else do-something-else end

However, this will not work if f is an object for which there is a "function"
tag method.

>What I figured out, is trying to invoke the function in question using
>"call", providing own handler.

This should work in all cases.

>Does anybody know nicer solution?

What exactly are you trying to do?
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Q: A way to determine if function is defined

Erik Hougaard
What is the status on 3.3 - That version should give better error
messages ?

/Erik

Reply | Threaded
Open this post in threaded view
|

Re: Q: A way to determine if function is defined

Maciej Maczynski
In reply to this post by Luiz Henrique de Figueiredo

> >From [hidden email]  Tue Mar 14 08:39:35 2000
> >From: "Maciej Maczynski" <[hidden email]>
> >
> >Is there a method in Lua to check from within a script if the function is
> >defined?
>
> To check whether f(x,y,z,...) is ok, just do
> if type(f)=="function" then f(x,y,z,...) else do-something-else end
>

Thanks!

> However, this will not work if f is an object for which there is a
"function"
> tag method.
>
> >What I figured out, is trying to invoke the function in question using
> >"call", providing own handler.
>
> This should work in all cases.
>
> >Does anybody know nicer solution?
>
> What exactly are you trying to do?

I have embedded Lua in my "main" application. It is extended with bunch of C
functions (for data communications).
I also have a test program, which embedds Lua too, but  (intentionally)
misses some functions, available only in "main" application.
I'd like the scripts to run both with test and "main" programs.  Threre are
other solutions to that problem too, but
I just wanted to know how to "detect" function.

Thanks for quick answer,
Maciej