Transferring Python globals and locals to Lua

211 Views Asked by At

I'm trying to write Pyton 3 wrapper for eval() function for Lua source strings.

For executing Lua expressions in Python I use eval() from Lupa library. But signature of eval() in Lupa is differ from Python built-in eval():

  • Lupa eval: eval(source: str),
  • Python eval: eval(source: str, globals: dict, locals: dict).

Of course, if globals and locals are None, I can simply write my function. Calling Lupa's eval within self-wrintten eval is enough for this:

import lupa

lua_run = lupa.LuaRuntime(unpack_returned_tuples=True)

def eval(expression, globals=None, locals=None):
    return lua_run.eval(expression)

But what I have to do if I want to transfer non-empty globals and locals dictionaries?

Maybe, it isn't possible in Lupa and I have to use some other libraries?

0

There are 0 best solutions below