[prev in list] [next in list] [prev in thread] [next in thread]
List: lua-l
Subject: Re: Lua Digest, Vol 174, Issue 1
From: Roberto Ierusalimschy <roberto () inf ! puc-rio ! br>
Date: 2009-09-28 16:05:43
Message-ID: 20090928160543.GA7843 () inf ! puc-rio ! br
[Download RAW message or body]
> 2009/9/28 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
> >> You can already associate any kind of information to a function by
> >> using it as a weak key in a Lua table. However you need access to the
> >> debug library to access built-in informations, or simply to allow a
> >> function to get a reference to itself to use as a key in the weak
> >> tables I mentioned.
> >
> > You do not need any reference; the function itself can be the key.
>
> I meant something like that:
>
> local ptypes = {}
>
> function foo(a)
> assert(type(a)==ptypes[debug.getinfo(1, 'f').func][1], "invalid
> parameter type")
> return a + 42
> end
> ptypes[foo] = {'number'}
>
> Is there any other way to use the currently executing function as a key ?
No; you are right.
-- Roberto
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic