Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ENH: Cleanup script loading #1511

Closed
EmosewaMC opened this issue Mar 26, 2024 · 1 comment · Fixed by #1579
Closed

ENH: Cleanup script loading #1511

EmosewaMC opened this issue Mar 26, 2024 · 1 comment · Fixed by #1579
Labels
enhancement New feature or request P-Fixer This issue is confirmed, but is not prioritized to be fixed.

Comments

@EmosewaMC
Copy link
Collaborator

Is your feature request related to a problem?

Script loading is quite clunky as it stands right now, given its form of a giant if else block, we would like to see it be cleaned up a bit.

Describe the solution you'd like

Instead of the if else chain in the script loader, something like the following is wanted:

map<string, std::function<CppScripts::Script*()>> ScriptLoader = {
        {"scripts/test.lua", [](){ return new Test(); } },
        {"scripts/foo.lua", [](){ return new Foo(); } },
        // and so it goes
 };

When creating the initial copy of a script, the following would be done:

map<string, std::function<CppScripts::Script*()>> ScriptLoader = {
        {"scripts/test.lua", [](){ return new Test(); } },
        {"scripts/foo.lua", [](){ return new Foo(); } },
        // and so it goes
 };
std::map<string, CppScripts::Script*> cache;

CppScripts::Script* GetScript(string script_name) {
auto itr = cache.find(script_name);
if (itr != cache.end()) return itr->second;
auto itrLoad = ScriptLoader[script_name];
if (itrLoad == ScriptLoader.end()) {
    cache[script_name] = InvalidScript;
    return InvalidScript;    
}
auto toReturn = itrLoad->second();
cache[script_name] = toReturn;
return toReturn;
}

Repository breaking implications

During the migration, its possible an error could cause a script to be missing accidentally due to a typo or another issue

Describe alternatives you've considered

modifying windows build to support if else chains longer than 128 blocks

Additional context

Shoutouts windows for enforcing a limit that doesnt need to exist

@EmosewaMC EmosewaMC added enhancement New feature or request triage An issue that needs triage P-Fixer This issue is confirmed, but is not prioritized to be fixed. and removed triage An issue that needs triage labels Mar 26, 2024
@EmosewaMC
Copy link
Collaborator Author

Note: This issue is for someone else for right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P-Fixer This issue is confirmed, but is not prioritized to be fixed.
Projects
None yet
1 participant