I have been trying to find and implement a library to decode JSON. After searching the discussions I saw a few people saying they have had success using dkjson. I have tried for a while now to get the dkjson module to work but need some help.
Currently I have a project with two tabs: one for the dkjson module and one a main where I am trying to implement it. The library says to import it using " json = require(“dkjson”) " in the regular Lua environment but I have yet to find how to properly call it in Codea.
That library seems to be better.
It still didn’t work at first, I learned that I couldn’t just get rid of the require lines. I had to change them so that:
local math = require(‘math’)
is now:
local math = _G.math
local string = require(“string”)
is now:
local string = _G.string
local table = require(“table”)
is now:
local table = _G.table
I’m not quite sure what this is doing so if someone can elaborate I’d love to know. Thanks for pointing me to that though!
Those lines would “require” or “import” the math, string and table function libraries into local table instances for improved access speed. require’ing the same library over and over is ok as the require function checks to see if the table is already loaded and if so returns a reference to it instead.
What your doing is replacing the require with local references to the same tables that have already been loaded and stored in the global table (_G) which is basically the same thing (or at least achieves the same results - stores a local reference for increased access speed)