ryobg / JContainers

JSON-based data structures for Papyrus - the TESV Skyrim SE scripting language
MIT License
107 stars 23 forks source link

Propositon to change JMap.objectWithTable implementation #79

Open CarlosLeyvaAyala opened 3 years ago

CarlosLeyvaAyala commented 3 years ago

Hi. I want to propose a change to the implementation of JMap.objectWithTable in jc.lua.

Current implementation only changes the Lua table at a superficial level, thus not converting nested Lua tables to JMap.

I did this and seems to work quite fine:

function JMap.objectWithTable(t)
  local object = JMap.object()
  for k,v in pairs(t) do
    if type(v) == "table" then
      object[k] = JMap.objectWithTable(v)
    else
      object[k] = v
    end
  end
  return object
end

Nothing too fancy, as you can see. Only a recursive call to deep converting the table.

ryobg commented 2 years ago

Is this still a valid request? I'm reluctant to change existing functions behaviour. A new one might be better idea.

CarlosLeyvaAyala commented 2 years ago

Yeah. It still is.

I used it quite A LOT in real "production" code and always worked reliably as expected.

Maybe a new function is a good idea, but still, I know the code works.