Not missing the files, all were there but somehow script.def location isn't recognized when try load it in pxy.
table.lua
Code:
function table.length(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end function table.find(t, value) for k,v in pairs(t) do if v == value then return k end end return nil end function table.findIndex(t, value) local i = 1 for k,v in pairs(t) do if v == value then return i end i = i + 1 end return 0 end function table.merge(a, b) if type(a) == 'table' and type(b) == 'table' then for k,v in pairs(b) do if type(v)=='table' and type(a[k] or false)=='table' then table.merge(a[k],v) else a[k]=v end end end return a end function table.print ( t ) local print_r_cache={} local function sub_print_r(t,indent) if (print_r_cache[tostring(t)]) then print(indent.."*"..tostring(t)) else print_r_cache[tostring(t)]=true if (type(t)=="table") then for pos,val in pairs(t) do if (type(val)=="table") then print(indent.."["..pos.."] => "..tostring(t).." {") sub_print_r(val,indent..string.rep(" ",string.len(pos)+8)) print(indent..string.rep(" ",string.len(pos)+6).."}") elseif (type(val)=="string") then print(indent.."["..pos..'] => "'..val..'"') else print(indent.."["..pos.."] => "..tostring(val)) end end else print(indent..tostring(t)) end end end if (type(t)=="table") then print(tostring(t).." {") sub_print_r(t," ") print("}") else sub_print_r(t," ") end print() end
ScriptingContext.cpp
Code:
Pyx::Scripting::ScriptingContext& Pyx::Scripting::ScriptingContext::GetInstance() { static ScriptingContext ctx; return ctx; } Pyx::Scripting::ScriptingContext::ScriptingContext() { } Pyx::Scripting::ScriptingContext::~ScriptingContext() { } void Pyx::Scripting::ScriptingContext::Initialize() { ReloadScripts(); } void Pyx::Scripting::ScriptingContext::Shutdown() { for (auto* pScript : m_scripts) { pScript->Stop(); delete pScript; } m_scripts.clear(); } void Pyx::Scripting::ScriptingContext::ReloadScripts() { PyxContext::GetInstance().Log(XorStringA("[Scripting] Reloading scripts ...")); const auto& pyxSettings = PyxContext::GetInstance().GetSettings(); for (auto* pScript : m_scripts) { if (pScript->IsRunning()) pScript->Stop(); delete pScript; } m_scripts.clear(); WIN32_FIND_DATA ffd; HANDLE hFind = INVALID_HANDLE_VALUE; DWORD dwError = 0; hFind = FindFirstFileW(std::wstring(pyxSettings.RootDirectory + pyxSettings.ScriptsDirectory + L"\\*").c_str(), &ffd); if (INVALID_HANDLE_VALUE == hFind) return; do { if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { auto fileName = pyxSettings.RootDirectory + pyxSettings.ScriptsDirectory + L"\\" + std::wstring(ffd.cFileName) + L"\\script.def"; auto scriptName = std::wstring(ffd.cFileName); DWORD dwAttrib = GetFileAttributesW(fileName.c_str()); if (dwAttrib != INVALID_FILE_ATTRIBUTES && !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) { ScriptDef scriptDef{ fileName }; if (scriptDef.IsScript()) { PyxContext::GetInstance().Log(XorStringW(L"[Scripting] Found script \"%s\""), scriptDef.GetName().c_str()); m_scripts.insert(new Script(scriptDef.GetName(), fileName)); } } } } while (FindNextFileW(hFind, &ffd) != 0); }
Code:
namespace Pyx { class PyxContext; namespace Scripting { class Script; class ScriptingContext { public: typedef void OnStartScriptCallback(Script& script); public: static ScriptingContext& GetInstance(); private: std::set<Script*> m_scripts; Utility::Callbacks<OnStartScriptCallback> m_OnStartScriptCallbacks; public: explicit ScriptingContext(); ~ScriptingContext(); void Initialize(); void Shutdown(); void ReloadScripts(); std::set<Script*> GetScripts() const { return m_scripts; } Utility::Callbacks<OnStartScriptCallback>& GetOnStartScriptCallbacks() { return m_OnStartScriptCallbacks; }; template<typename... Args> void FireCallbacks(const std::wstring& name, Args&&... args) { for (Script* pScript : m_scripts) { if (pScript->IsRunning()) { pScript->FireCallback(name, std::forward<Args>(args)...); } } } }; } }
Code:
namespace Pyx { namespace Scripting { class ScriptDef { public: ScriptDef(std::wstring fileName); const std::wstring GetName(); const std::wstring GetType(); bool IsScript() { return GetType() == L"script"; } bool IsLib() { return GetType() == L"lib"; } std::vector<std::wstring> GetFiles(); std::vector<std::wstring> GetDependencies(); bool Validate(std::wstring& error); bool Run(LuaState& luaState); private: std::wstring m_scriptDirectory; std::vector<Utility::IniFile::SectionValue> m_scriptSection; std::vector<Utility::IniFile::SectionValue> m_filesSection; std::vector<Utility::IniFile::SectionValue> m_dependenciestSection; }; } }
Code:
namespace Pyx { struct PyxInitSettings { Pyx::GuiType GuiType = Pyx::GuiType::ImGui; std::wstring RootDirectory = L""; bool GuiBlockInput = false; bool LogToFile = true; std::wstring LogDirectory = L"\\Logs"; std::wstring ScriptsDirectory = L"\\Scripts"; }; }