Giter Club home page Giter Club logo

Comments (3)

scoder avatar scoder commented on August 30, 2024

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.

kmike avatar kmike commented on August 30, 2024

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.

scoder avatar scoder commented on August 30, 2024

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 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?

"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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.