[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Idea (unsafe): a variant of lua_getstack
- From: Jay Carlson <nop@...>
- Date: Tue, 21 Feb 2012 12:28:41 +0000
On Tue, Feb 21, 2012 at 9:23 AM, Eduardo Ochs <eduardoochs@gmail.com> wrote:
> Two questions - one technical, one not...
>
> 1) Is there a way to flag clearly to the list that a certain idea is
> for a low-level/dangerous hack ONLY
No. You Will Be Flamed.
> 2) I would like to experiment with variants of lua_getstack,
> debug.getinfo, debug.getlocal and debug.setlocal - see:
> and this pseudocode, where _L is a table that gives access to the
> local variables of the function "outer":
>
> inner = function (_L)
> print(_L.a) --> 22
> _L.a = 33
> end
> outer = function ()
> local a = 22
> _L = setmetable({}, {__index = ..., __newindex = ...})
> print(a) --> 22
> inner(_L)
> print(a) --> 33
> end
> outer()
I would think this would be possible to do safely as long as the
activation record for outer was live. Could you live with this only
being available on coroutines? That sounds easy.
Another possibility is to have something a lot like xpcall:
call_with_locals(f), which calls f with argument _L referring to its
own locals. _L would be implemented as a userdata with the address you
describe in it, and exit from call_with_locals would NULL it out.
xpcall is our unwind-protect....
I bet any of this will make luajit very Sad.
>From bash's unwind_prot.c (
http://git.savannah.gnu.org/cgit/bash.git/tree/unwind_prot.c ):
| /* unwind_prot.c - a simple unwind-protect system for internal variables */
|
| /* I can't stand it anymore! Please can't we just write the
| whole Unix system in lisp or something? */
|
| /* Copyright (C) 1987-2009 Free Software Foundation, Inc.
Pretty sure that was there back in the bash 1.0 days.
Jay