convert a python function in py_to_lua
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?
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')