1

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?

VeLKerr
  • 2,995
  • 3
  • 24
  • 47
  • You can access the tables from inside Lua, allowing you to setfenv/_ENV for globals. – EinsteinK Feb 19 '16 at 14:58
  • And the debug library can be used to get a list of locals: http://stackoverflow.com/questions/2834579/print-all-local-variables-accessible-to-the-current-scope-in-lua – warspyking Feb 20 '16 at 01:05

0 Answers0