lua-users home
lua-l archive

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


Hi!
 
I have a question about Lua/C API (5.1) usage:
Is it valid to raise an error on protected, non-currently executed coroutine?

Here [1] is the example.
The interesting part is lua_CFunction throw_error_at_old_thread():

| static int throw_error_at_old_thread(lua_State *cur_L)
| {
|     lua_error(old_L);

The Lua Reference Manual (5.4) declares that:

| As a general rule, when a C function is called by Lua with a Lua state,
| it can do whatever it wants on that Lua state, as it should be already
| protected.  However, when C code operates on *other* Lua states (e.g., a
| Lua-state argument to the function, a Lua state stored in the registry,
| or the result of lua_newthread), it should use them only in API calls
| that cannot raise errors.

In my opinion, "other" means "not protected", but Mike Pall says, that
it means "not currently executed" [2].

For the Lua 5.1 this operation seems valid to me. Are there any hidden
hazards, that I've missed? Note, that values on the stack doesn't
bother me, assume I manage them carefully in case with/without error.

[1]: https://gist.github.com/Buristan/7009d8e0cc8e7c11291b2c6694cb847b
[2]: https://github.com/LuaJIT/LuaJIT/pull/740#issuecomment-897173357
 
--
Best regards,
Sergey Kaplun