[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Detecting function or "method" call
- From: lua@...
- Date: Tue, 15 Apr 2008 16:57:58 +0200
* On 2008-04-15 Matias Guijarro <matias.guijarro@free.fr> wrote :
> Hello :-)
>
> Sorry if the question has already been asked, but I could not
> find any answer on the list so here it is :
>
> Is there a way to detect if a function in a table should be called
> as a "method" (OO style), e.g foo:bar() or if it has to be called
> as a function - foo.bar() ?
>
> Consider a XML-RPC server in Lua : exported functions and
> "objects" in the global environment are available for clients. If
> a client makes a request like this : "foo.bar", the server needs
> to know how to execute the request.
>
> Is there some debug library magic to be able to have a hint ?
> I wonder, because for example if we know that the first
> argument of function "bar" is "self", it probably indicates
> that it should be called with ":" ... Well, even that is not a
> good solution :-(
A pragmatic solution: depending on the way you implemented your OO-style
objects, you could verify if the first argument is a table, and if it
holds a magic item that you put in there when the object was created.
--
:wq
^X^Cy^K^X^C^C^C^C