Skip to content

How to convert LUA Table to javascript object #49

@stackola

Description

@stackola

My question is basically in the title.

Is there a way to convert a table passed in from LUA to native JS?

{key:value} objects seem to work alright, but [value, value, value] arrays do not.

Here's an example:

Lua:

{obj = {key = "value"},  str = "string", arr = {1,2,3} }

Calling an environment function..

JS:

{
  "obj": {
    "__shine": {
      "type": "table",
      "index": 55,
      "keys": [],
      "values": [],
      "numValues": [
        null
      ],
      "refCount": 1
    },
    "key": "value"
  },
  "str": "string",
  "arr": {
    "__shine": {
      "type": "table",
      "index": 56,
      "keys": [],
      "values": [],
      "numValues": [
        null,
        1,
        2,
        3
      ],
      "refCount": 2
    }
  }
}

What I wanted:

{
  "obj": {
    "key": "value"
  },
  "str": "string",
  "arr": [
    1,
    2,
    3
  ]
}

This would obviously need to be done in a recursive manner.

Does a functionality like this exist already?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions