Jump to content

Recommended Posts

Posted

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!

Posted

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

Let's build cool stuff and have fun. :)

Posted

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!

  • 1 year later...
Posted
On 7/29/2024 at 1:11 AM, Josh said:

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;
}

 

Has this main CPP file changed since the script editor was introduced? It seems like the internal debugger no longer works with this code.

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

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

Posted
#include "Leadwerks.h"
#include "Steamworks/Steamworks.h"

using namespace Leadwerks;

void ExecuteDir(std::shared_ptr<Package> package, const WString& path, const bool recursive)
{
    std::vector<WString> dir;
    int type;
    if (package)
    {
        dir = package->LoadDir(path);
    }
    else
    {
        dir = LoadDir(path);
    }
    for (auto file : dir)
    {
        WString filepath = path + "/" + file;
        auto ext = Leadwerks::ExtractExt(file).Lower();
        if (package)
        {
            type = package->FileType(filepath);
        }
        else
        {
            type = FileType(filepath);
        }
        switch (type)
        {
        case 1:
            if (ext == "lua" or ext == "luac")
            {
                RunScript(filepath);
            }
            break;
        case 2:
            if (recursive) ExecuteDir(package, 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); });

    //Load packages
    auto dir = LoadDir("");
    std::shared_ptr<Package> datapackage;
    if (FileType("data.zip") == 1)
    {
        datapackage = LoadPackage("data.zip");
    }
    
    //Run the error handler script
    RunScript("Scripts/System/ErrorHandler.lua");

    //Enable the integrated debugger if needed
    if (settings["debugport"].is_integer())
    {
        int debugport = settings["debugport"];
        int debugtimeout = 10000;
        int debuglevels = 4;
        String breakpoints;
        if (settings["debugport"].is_integer()) debugport = settings["debugport"];
        if (settings["debugtimeout"].is_integer()) debugtimeout = settings["debugtimeout"];
        if (settings["debuglevels"].is_integer()) debuglevels = settings["debuglevels"];
        if (settings["breakpoints"].is_string()) breakpoints = settings["breakpoints"];
        if (ConnectDebugger(debugport, debugtimeout, debuglevels, breakpoints))
        {
            Print("Connected to debugger on port " + String(debugport));
        }
        else
        {
            Print("Error: Failed to connect to debugger on port " + String(debugport) + " after " + String(debugtimeout) + " milliseconds");
        }
    }

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

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

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

    //Run component scripts
    dir = LoadDir("Scripts/Entities");
    for (auto file : dir)
    {
        int type;
        if (datapackage)
        {
            type = datapackage->FileType("Scripts/Entities/" + file);
        }
        else
        {
            type = FileType("Scripts/Entities/" + file);
        }
        if (type == 2)
        {
            ExecuteDir(datapackage, "Scripts/Entities/" + file, false);
        }
    }

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

    return 0;
}

 

  • Thanks 1

Let's build cool stuff and have fun. :)

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.

×
×
  • Create New...