Comments (3)
Is it a bug or an intended behaviour?
from lupa.
At least, it doesn't crash. These things used to. :)
Note that the pcall(lua_func)
essentially just unpacks both Lua functions and calls one with the other as argument inside of Lua, so the Lua error doesn't actually pass through Python at all here.
The other way is tricky because supporting pcall(), correct me if I'm wrong, would mean that we translate a Python exception into a Lua longjmp() error to pass it on to Lua, and then detect and translate it back into a Python exception when it turns out that Lua didn't handle it and passed it back to Lupa (i.e. when there is no pcall() wrapping it).
I wouldn't call it "intended behaviour", but I'm not sure it's worth changing.
from lupa.
I see, thanks for explanation.
I worked around it by wrapping Python functions to a decorator that converts Python exceptions to False, repr(exception)
and return values to True, result
; in Lua these Python functions are wrapped in a Lua decorator which raises an error if status is False (these errors can be catched by pcall) and returns the result otherwise.
This means that Python exceptions are not propagated back to Python as-is when they are not handled, they are converted to LuaErrors. For my use cases it is even better because for these new errors error messages include line numbers. Maybe in future I'll attach original Python exception objects to errors as userdata; for the current use cases repr is enough.
It seems both behaviours have their use cases: raising original errors and raising wrapped errors, even in a single runtime.
At the moment I don't have plans to work on it further because an existing solution works well enough, but supporting something like this directly in lupa could help to clean up some of the messy code. Creating an existing workaround was quite tricky, and it has edge cases with coroutines (Python decorator doesn't fix values sent using coroutine.send).
from lupa.
Related Issues (20)
- Error loading C modules in 2.x HOT 6
- Expose Lua load arguments (mode and chunkname) HOT 9
- Identity of wrapped Lua objects
- Deadlock involving __dealloc__ HOT 3
- [Feature Request] Async Overhaul
- [Feature Request] Expose Guts for better fine control.
- Ship Lua 5.1 with default lupa installation HOT 3
- pip install lupa fails on Windows HOT 2
- Terra HOT 1
- question: using python functions on lua tables HOT 2
- error lupa.lua54.LuaSyntaxError:
- Can Chinese name function functions be supported?
- Can't install lupa using pip HOT 3
- lua51 missing HOT 1
- 2.1 `pip install --upgrade lupa` not enough, `--force-reinstall` was needed HOT 4
- Unable to Import 'lua-utf8' in LuaJIT HOT 1
- 2.1: pytest fails in `lupa/tests/test.py::TestOverflowMixin::test_no_overflow` unit HOT 8
- Cython error: Lua "undeclared name not builtin: long" HOT 2
- 'popen' not supported
- How to pass a python dictionary as an argument into a function defined in LUA code?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lupa.