I struggle to find a working solution for parsing multidimensional LUA table with ElectronJs (nodeJS) into a json.
I’ve tried already the lua-in-js package but i always get syntax errors, no matter how i try to implement it, it’s just always syntax errors within the LUA code.
The code looks something like this.
const luaPath = process.cwd() + '\lua';
const json4luaCode = readFileSync(json4luaFile, 'utf-8');
const luaEnv = luainjs.createEnv({
fileExists: p => existsSync(join(luaPath, p)),
loadFile: p => readFileSync(join(luaPath, p), { encoding: 'utf8' })
})
const luaCode = `
dofile(${json4luaFile})
local json_data = json.encode(LuaDatabase)
print(json_data)
`;
const luaScript = luaEnv.parse(luaCode)
const returnValue = luaScript.exec()
I am dependable on external LUA scripts to parse the LUA Tables, because i believe the lua-in-js package doesn’t have all native LUA functions compared to the installed LUA binary files.
I have a working LUA script, which successfully transforms the LUA Table into json, when i run it directly with LUA. But i can’t get it to work within NodeJS. Does anyone have experience with that?
This is my LUA script which works directly executed with LUA (i can just pass the LUA Table as a parameter to the script):
local params = {...}
dofile(params[1])
local json = require("json")
local json_data = json.encode(LuaDatabase) --name if the table
print(json_data)