Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert a python function in py_to_lua #83

Open
oeway opened this issue Nov 3, 2016 · 1 comment
Open

convert a python function in py_to_lua #83

oeway opened this issue Nov 3, 2016 · 1 comment

Comments

@oeway
Copy link

oeway commented Nov 3, 2016

Hi,

I am trying to pass a python function as argument into a function defined in lua code, it complaining that: LuaError: XXXXXX.lua:44: attempt to call local 'opfunc' (a table value).

def tuple_fun():
    return "one", "two", "three", "four"
lua.globals()['fun'] = tuple_fun

lua.eval('type(fun)')
# output userdata

lua.eval('type(python.as_function(fun))')
# output function

I know that by using python.as_function in lua code can make lupa recognize the object as a function, but in my case, the lua code is not possible to change because it's in a third party library, I try to call the function in lupa code.

I checked the code in _lupa.pyx, in the function named py_to_lua, why not just convert the python function into a lua object? or add the python.as_function automatically?

Can anyone help?

@jbinary
Copy link
Contributor

jbinary commented Nov 4, 2016

It's hard to say what was the problem exactly without seeing the third party library code which results in the error.
But it's perfectly fine to run python function from lua without any conversions, here is a continuation for your example:

>>> lua.eval('function(f) return f() end')(tuple_fun)
Out[11]: (u'one', u'two', u'three', u'four')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants