Conversation
|
Can you review this, @scoder ? |
* Make lock_runtime return boolean and not raise error directly * If check_lua_stack fails on _LuaRuntimeStack.__enter__, unlocks LuaRuntime, avoiding the resource to be acquired forever * Use _LuaRuntimeStack in py_to_lua_custom (unrolls stack on Python error) * Use _LuaRuntimeStack in py_to_lua_overflow (catches error on py_to_lua_custom) * Add preconditions and postconditions to important functions/methods * Add assertion for extra >= 0 on check_lua_stack (would violate Lua C API precondition and probably cause undefined behaviour) * Lock LuaRuntime instance on _fix_args_kwargs and ensure 1 Lua stack slot
|
Did you test if this has any performance impact? (I.e., can you prove that it doesn't?) |
Previously, with the context handler it was 50% the speed. |
|
Note that |
|
I change my mind -- I think it's fine the way it is, explicit and efficient. |
|
Could you review this, @scoder? It makes Lupa more reliable, in that we guarantee we can push new values to the Lua stack. |
|
Yes, this looks very clean and helpful. |
|
Let's get this merged, @scoder ? I depend on it for future PRs. |
|
Works for me. Thanks! |
Some places don't lock the LuaRuntime before fiddling with the Lua stack, and many places don't ensure extra slots either.
This PR also involves other changes:
_LuaObject.__str____tostringdoesn't exist, use_LuaObject.__repr____tostringreturns non-string value, raise aTypeError__tostringraises an error, raise aLuaErrorlua_pushglobaltableinstead of pushing_G, which may not point to the global table.lock_runtimereturn boolean and not raise error directlyLUA_NOREFandLUA_REFNILconstants for effective handling of Lua referencesLuaRuntime._stateis notNULL, and if_LuaObject._runtimeisNone, etc...)