reepblue Posted July 28 Share Posted July 28 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. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted July 29 Share Posted July 29 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; } 1 Quote 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 More sharing options...
reepblue Posted July 30 Author Share Posted July 30 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); } Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
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.