Jump to content

CommandLine() Exposure Source


reepblue
 Share

Recommended Posts

The source for the Lua app seems to be out of date. Not only it still references the scripts are located under a script folder, but my main issue is that the function "CommandLine()" isn't valid in my application while I was thinking it was part of the engine's API. 

Can I get the source for this, or can this actually be in the engine so I can recreate the Lua application myself? I want my application to use Lua but have my C++ systems integrated and exposed using sol. 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

It's like this:
 

#include "UltraEngine.h"
#include "Steamworks/Steamworks.h"

using namespace UltraEngine;

void ExecuteDir(const WString& path, const bool recursive)
{
    auto dir = LoadDir(path);
    for (auto file : dir)
    {
        WString filepath = path + "/" + file;
        switch (FileType(filepath))
        {
        case 1:
            if (ExtractExt(file).Lower() == "lua")  RunScript(filepath);
            break;
        case 2:
            if (recursive) ExecuteDir(filepath, true);
            break;
        }
    }
}
 
int main(int argc, const char* argv[])
{
    //Get commandline settings
    auto settings = ParseCommandLine(argc, argv);

    auto L = GetLuaState();
    Steamworks::BindCommands(L);
    L->set_function("CommandLine", [settings]() { return tableplusplus::tablewrapper(settings); });

    //Run the error handler script
    RunScript("Source/System/ErrorHandler.lua");

    //Enable the debugger if needed
    shared_ptr<Timer> debugtimer;
    if (settings["debug"].is_boolean() and settings["debug"] == true)
    {
        RunScript("Source/System/Debugger.lua");
        debugtimer = CreateTimer(510);
        ListenEvent(EVENT_TIMERTICK, debugtimer, std::bind(PollDebugger, 500));
    }

    //Run the component system helper
    RunScript("Source/System/ComponentSystem.lua");

    //Run user start scripts
    ExecuteDir("Source/Start", false);

    //Run component scripts
    auto dir = LoadDir("Source/Components");
    for (auto file : dir)
    {
        if (FileType("Source/Components/" + file) == 2)
        {
            ExecuteDir("Source/Components/" + file, false);
        }
    }

    //Run main script
    RunScript("Source/main.lua");

    return 0;
}

 

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

This was very helpful, thank you. 

One change I added was this function that will preference the .luac version of the script if present. I replace all my RunScript calls with this. 

bool RunCompiledScript(const WString& path)
{
    auto p = StripExt(path);

    // If there is a .luac version of this file, run it instead.
    if (FileType(p + ".luac") != 0) return RunFile(p + ".luac");
    
    return RunScript(path);
}

 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...