lua-users home
lua-l archive

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


 

I have defined an asynchronous function in C that yields the current thread and then resumes it when the operation completes.  If the function succeeds, then I push the result onto the stack and call lua_resume().

     

What can I do in case of an exception? I’d love to somehow cause an exception to be thrown into the resumed thread, but I don’t see an easy way to do this.

 

So far I’ve considered injecting some Lua shim code, but that seems pretty complicated:

 

 

 

-- Get the async function from the stack

f = ...

 

-- Call the async function. It will return true on success and false on failure

success, result = f() 

 

if success then

      return result    -- the 2nd argument is the result. TODO: Handle tuple results.

else

      error(result)    -- the 2nd argument is the error message. Throw it.

end

 

 

 

 

I’d much rather not go down this complicated (and inefficient) route if I can avoid it. Any ideas?

 

-Erik