lua-users home
lua-l archive

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


On Thu, Feb 24, 2011 at 6:24 PM, Joshua Jensen <josh.jjensen@gmail.com> wrote:
> I'd love to find a patch that just does injection of the code in this manner:
>
>     function Func()
>         running = true;  -- finalize running = false end
>         if somebadthing then
>             running = false    --!!!!!!
>             return false
>         end
>         mutex:lock();  -- finalize mutex:unlock() end
>         if running then
>             mutex:unlock()  --!!!!!!
>             running = false   --!!!!!!
>             return false
>         end
>         mutex:unlock()     --!!!!!!
>         running = false      --!!!!!!
>         return Idle_loop()  -- Tail call
>     end

That should be straightforward enough, either as a patch to lparser.c
or as an external source preprocessor, neither of which require VM
changes.  The downside is that it doesn't cleanup properly on exits
due to raised errors.  (More difficult to address are out-of-memory
errors if allowed to occur anywhere [1].)

I would have thought the cleanup should occur after the idle_loop(),
as it does in C++, which would seem to prevent the tail call
optimization, but there may be justification for cleanup prior to the
tail call as your example shows.

[1] http://lua-users.org/lists/lua-l/2008-10/msg00396.html