Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Can't use LogicEngine::saveToFile() with UTF-8-based string data on Windows #40

Open
ParadoxDaKo opened this issue Mar 18, 2022 · 2 comments

Comments

@ParadoxDaKo
Copy link

ParadoxDaKo commented Mar 18, 2022

RLogic version: 0.14.2

For file paths, we are using UTF-8-based strings to support non-ASCII data such as Umlauts or Chinese letters.

LogicEngine::saveToFile() does not seem to handle UTF-8 string data, falsely decoding it in the process of saving an RLogic file on Windows systems.

Here is a GTest that elucidates the problem:

TEST(ramses_logic, saveToFile_withUmlauts) {
    rlogic::LogicEngine logicEngine;
    auto scriptContentFloat{
        R"(
function interface()
    IN.float = FLOAT
    OUT.float = FLOAT
end

function run()
    OUT.float = math.cos(IN.float)
end
)"};

    auto luaConfig = raco::ramses_base::defaultLuaConfig();
    auto* script = logicEngine.createLuaScript(scriptContentFloat, luaConfig);

    std::filesystem::path path("saveToFile_äöü.ramses");

    logicEngine.saveToFile(path.u8string());

    // use simple const char* data here
    auto status = logicEngine.loadFromFile(path.generic_string());

    ASSERT_TRUE(status);
}

In this test case, RLogic will save a file with the filename saveToFile_äöü.ramses but try to load a file with the filename saveToFile_äöü.ramses.

@violinyanev
Copy link
Member

That is because you are depending on platform-specific behavior ;) Straight from the docs:
image

Will document a bit better that the string_view is an ASCII string, not utf8 string. Adding non-ascii support for file saving will unnecessarily complicate the logic engine. But we can add a function to save to byte buffer, not a file, and you can use that to use your own file-string handling logic - would that work for you?

@ParadoxDaKo
Copy link
Author

Yes, this looks like a good idea - if there was the same functionality for Ramses then I would be 100% happy 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants