lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I've written Lua code that uses getfenv with a series of increasing indices
to walk up the call stack looking for a function environment that defines a
particular variable. This creates sort of a dynamic scoping effect. The Lua
code right now, however, has no way to detect when to stop looking and
instead just relies on catching the exception when the index gets too high.
I'm somewhat loathe to use exceptions for a non-exceptional condition.

I don't have a problem with writing this in C if that will work better, but
I figured that I'd try doing it in pure Lua first.

Mark

P.S. My specific usage: When I need to load resources such as images for
some GUI code, I need to know what directory to look in. What I'm trying to
make work is something where when I load a piece of code, I give it a custom
environment that includes a variable pointing to the directory it came from.
Then I can just search up the call chain looking at directories until I find
one containing the named image.

on 12/18/03 12:06 AM, Leandro Candido at enclle@click21.com.br wrote:

> Hello Mark,
> 
>   Can you better explain what you want? Are you making this in C or in
> Lua? Are you using the debug api?
>   What you want is to limit the access for getfenv?
> 
>                                                                   The
> God's Peace,
> 
> 
> Leandro.
> ----- Original Message -----
> From: "Mark Hamburg" <mhamburg@adobe.com>
> To: "Lua list" <lua@bazar2.conectiva.com.br>
> Sent: Wednesday, December 17, 2003 11:14 PM
> Subject: getfenv question
> 
> 
>> Is there a way other than wrapping things in pcall to tell what the
> maximum
>> level I can pass to getfenv is?
>> 
>> I'm trying to implement pseudo-dynamic scoping by searching up the call
>> chain for the first function environment referencing a particular
> variable.
>> 
>> Mark
>> 
>> 
>