Skip to content

question: using python functions on lua tables #259

@amm0x41r

Description

@amm0x41r

Hello,
Sorry for the noob question, but I can't quite figure it out.
I'm trying to use the Python JSON lib instead of any of the lua ones due to issues with package installation on target, but I can't get even the minimal example to work. Here's what I'm trying:

import lupa
import json

lua = lupa.LuaRuntime(unpack_returned_tuples=True)
lua.execute("json = {}")
lua.globals()["json"]["encode"] = json.dumps
lua.globals()["json"]["decode"] = json.loads
lua_function = """
function construct_json_list()
    local out = {"a", "b", "c"}
    return json.encode("throwaway", out)
end
"""
lua.execute(lua_function)
print(lua.globals()["construct_json_list"]())

This simply throws TypeError: Object of type _LuaTable is not JSON serializable. Obviously json.dumps does not support Lua Tables.

tl;dr how to convert a lua table to a python object?

Any help is appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions