For scripts that consist of multiple files

I would like to use a dictionary database for more accurate Korean pronunciation implementation. But to use it in a script, you have to hardcode the database. Is there any way to use multiple files including JSON, XML?

I’ve only done scripting in Lua, but I know that SynthesizerV also supports JavaScript.

In Lua, you can use the standard io library to read and write files. Although JSON and XML support aren’t built-in, there are JSON and XML libraries that are available for Lua.

If you are coding in Lua, it would probably make sense to store the data as a loadable Lua table instead of JSON or XML, as it’s trivial to read and write Lua tables.

However, there are some issues with Lua that you probably won’t experience in JavaScript.

First of all, thank you for your reply.

I also agree that it’s easy to use a built-in data structure like Lua’s table.
However, I thought that injecting data with hard-coding could make the code too bloated and cause maintenance difficulties.
(It may vary depending on the tokenizer, but the currently generated dictionary data is about 260,000 words without duplicates.)
(Also, I’m a Python developer, so I hate getting my code dirty. :sweat_smile:)

Since it is not only oversized, but there are several types of databases that need to be used, I’m considering separating them into multiple files.

By the way, I know that the library was not available, is there a way to use it?

There are “pure Lua” versions of JSON and XML parsers that you can find, such as:

Unfortunately, it doesn’t appear that ffi support is built into the version of Lua that comes with SynthV, or you’d be able to make calls to .DLLs and use things like SQLite.

You could just have the dictionary data as plain text and read it in. Lua’s file I/O is plenty fast - it should take a fraction of a second to read the file.

Oh, ‘require’ is available.
It was impossible in the duktape(js) implementation, so I thought it was impossible even in Lua.

When I run it myself, the ‘cwd’ of the Lua interpreter is the folder where “synthv-studio.exe” is located.

However, at the time of writing this article, I have only tested Windows, so I think I will have to try the Mac one more time tonight.

Thank you for the idea.

p.s. I tested ffi on Linux, Windows, and macOs, and there was a build issue in Apple Silicon.

This is example code using ‘json.lua’.

function getClientInfo()
    return {
        name = "Test",
        author = "PNCSS",
        versionNumber = 1,
        minEditorVersion = 0
    }
end

function main()
    json = require "json"
    SV:showMessageBox("title", json.encode({ 1, 2, 3, { x = 10 } }))
    SV:finish()
end

in macOs example.
It is same but you have to define ‘package.path’.

function getClientInfo()
    return {
        name = "Test",
        author = "PNCSS",
        versionNumber = 1,
        minEditorVersion = 0
    }
end

function main()
    package.path = package.path .. ";/Users/noel/?.lua"
    local json = require "json"
    SV:showMessageBox("title", json.encode({ 1, 2, 3, { x = 10 } }))
    SV:finish()
end
2 Likes