lua-users home
lua-l archive

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

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, and only meant as a prototype
   and for quick experiments that would be run only a handful of times
   and in very controlled environments? I would like to avoid getting
   answers like "don't do that, it's unsafe", "how would you handle
   GC?", "use userdata", "this won't work in architectures where
   pointers can not be represented faithfully as numbers"... Sometimes
   in a proof of concept it is better to leave all concerns with GC,
   safety, etc to a second moment...

2) I would like to experiment with variants of lua_getstack,
   debug.getinfo, debug.getlocal and debug.setlocal - see:

   in which the "level" parameter could also be given as a string of
   the form "0xhhhhhhhh", meaning the address in memory - without any
   kind of error checking - of an active function. Is there something
   like this around? I haven't started to write the code for this yet,
   and my C skills got quite rusty in the last years, so I'd rather
   start with someone else's code...

   If it is not clear how these variants could be useful, consider

     inner = function ()
         print(debug.getlocal(2, 1))      --> a 22
         print(debug.setlocal(2, 1, 33))  --> a
     outer = function ()
         local a = 22
         print(a)   --> 22
         print(a)   --> 33

   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
     outer = function ()
         local a = 22
         _L = setmetable({}, {__index = ..., __newindex = ...})
         print(a)   --> 22
         print(a)   --> 33

   It is possible to write the code for "_L" in standard Lua using the
   debug library, but that requires a lot of juggling with the stack

       Eduardo Ochs