lua-users home
lua-l archive

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


Here is what I'm doing. It seems to be working but the app hasn't been
running long with 5.1 and we have seen some other strangeness that I don't
believe is exception related.

1. L_TRY and L_THROW are defined to use Objective-C/Cocoa exceptions. These
are setjmp/longjmp based but they have their own stack.

2. The panic case stores the status code in the state and then throws an
exception.

The code that manages temporary states -- e.g., for calls from the OS event
loop into my code  -- arranges for states to be collected rather than
recycled if they are "returned" with the status field set to something other
than zero.

>From what you've said, this should all work. It would be nice if I didn't
need to patch the ldo.c to get it store the status value before calling the
panic function, but at least it's an easy patch to mark in the code.

Here is a slightly more concrete example:

    lua_State* L = acquireTempLuaState();
                        // Get a state from the "pool"

    @try {
        ... Do stuff with L that might fail ...
    }
    @finally {
        if( lua_threadstatus( L ) != 0 ) {
            freeTempLuaState( L );
                // Remove the registry entry that keeps the state alive
        } else {
            releaseTempLuaState( L );
                // Put the state back in the pool
        } 
    }

Does this seem reasonable as an approach?

Mark

on 11/29/04 11:00 AM, Roberto Ierusalimschy at roberto@inf.puc-rio.br wrote:

>> 3. The panic case documentation indicates that the "Lua" is
>> invalid. Is it the entire universe that is invalid or just this thread
>> within the universe?  Can I simply arrange for the thread to be
>> garbage collected?
> 
> Inside the Lua state it is just the thread. But you probably will
> have stacked C calls (after all, the whole point of a long jump is to
> remove such calls). So, unless you have a separated C stack for this
> thread (i.e., multithreading or C coroutines) the entire universe is
> compromised.
> 
> -- Roberto