Comments (3)
I didn't even know that feature in Lua, but it seems useful. It's described here:
http://lua-users.org/wiki/NamedParameters
I agree that it has to be done explicitly to prevent exploding all tables being passed into Python functions into separate arguments. A decorator sounds like a good way to do it. It also allows calling it directly on a Python function before passing it into Lua (i.e. not using it as a decorator but as a normal function).
Although, if users can prevent the case of passing single table arguments by accident, a global LuaRuntime() option might also do the trick. But then the opposite decorator would be required to prevent table explosion in those undesired cases where it accidentally turns out that it cannot be avoided after all.
Note that Lua allows both positional and keyword arguments to be passed through tables, so simply dropping the table into a dict is not sufficient. Testing len(table)
(or doing the equivalent Lua operation) should distinguish both cases.
from lupa.
Good catch about positional arguments. I'll add support for them and submit a PR (decorators.py
file with 2 public functions, also imported from __init__.py
).
Are table_arguments
and table_arguments_method
names OK, or do you have better names in mind? lua_named_parameters
and lua_named_parameters_method
? just lupa.named_parameters[_method]
? lupa.allow_named_parameters[_method]
? table_as_kwargs
?
Also, would you mind adding py.test or nose as a test runner?
from lupa.
decorators.py
file with 2 functions, also imported from__init__.py
I wouldn't mind adding them right in _lupa.pyx, should be faster.
Are
table_arguments
andtable_arguments_method
names OK, or do you
have better names in mind?lua_named_parameters
and
lua_named_parameters_method
? justlupa.named_parameters[_method]
?
lupa.allow_named_parameters[_method]
?table_as_kwargs
?
"unpack_lua_table"? "arguments_from_lua_table"?
It's not just about kwargs or named arguments, even though that's the main
use case.
Also, would you mind adding py.test or nose as a test runner?
py.test, if any, but unless there is an actual need for it, I'm quite happy
that you can currently run the test suite without installing external
Python dependencies.
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? HOT 1
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.