From 8446078851f5430e8315d6618d8d5dd9d6e3d1ab Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 19 Oct 2021 02:21:47 +0800 Subject: +LuaPanda --- Editor/EditorMain.cpp | 42 ++++++++++++++---------------------------- Editor/Path.cpp | 0 Editor/Path.h | 0 Editor/Win/Win.cpp | 18 ++++++++++++++++++ Editor/Win/Win.h | 14 ++++++++++++++ 5 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 Editor/Path.cpp create mode 100644 Editor/Path.h create mode 100644 Editor/Win/Win.cpp create mode 100644 Editor/Win/Win.h (limited to 'Editor') diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index f8ee4ef..5e0cf99 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -1,40 +1,15 @@ #include #include + #include "GUI/EditorWindows.h" #include "Runtime/Lua/LuaBind/LuaBind.h" #include "EditorManager.h" #include "Runtime/Graphics/OpenGL.h" #include "Editor/Scripting/EditorScripting.h" +#include "Editor/Win/Win.h" using namespace LuaBind; -static int MainLoop() -{ - BOOL returnValue; - MSG msg, lastMsg; - msg.message = WM_NULL; - std::vector messages; - PeekMessage(&msg, NULL, 0U, 0U, PM_NOREMOVE); - bool isQuitSignaled = msg.message == WM_QUIT; - - while (!isQuitSignaled) - { - MSG msg; - while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - - if (msg.message == WM_QUIT) - isQuitSignaled = true; - - } - - } - - return (INT)msg.wParam; -} - void ErrorHandle(cc8* msg) { log_error(std::string("[Lua] ") + msg); @@ -50,7 +25,18 @@ void InitLuaState() log_error("Can't setup scripting."); } LuaBind::State state = vm.GetMainState(); - state.DoFile("./Scripts/EditorApplication.lua", ErrorHandle); + + // https://stackoverflow.com/questions/21495901/loadlibrarya-and-relative-path/21495971 + // ll_load装载dll,路径需要设置搜索路径 + //log_info(Win::GetCurrentWorkingDirectory()); + std::string workingDir = Win::GetCurrentWorkingDirectory(); + Win::SetDllSearchDirectory(workingDir); + + // set cpath + state.DoString(R"(package.path=package.path .. ";" .. ".\\Libraries\\?.lua")"); + state.DoString(R"(package.cpath=package.cpath .. ";" .. ".\\Libraries\\?.dll")"); + + state.DoFile(".\\Scripts\\EditorApplication.lua", ErrorHandle); } #ifdef GAMELAB_DEBUG diff --git a/Editor/Path.cpp b/Editor/Path.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Editor/Path.h b/Editor/Path.h new file mode 100644 index 0000000..e69de29 diff --git a/Editor/Win/Win.cpp b/Editor/Win/Win.cpp new file mode 100644 index 0000000..f6310e2 --- /dev/null +++ b/Editor/Win/Win.cpp @@ -0,0 +1,18 @@ +#include "win.h" + +namespace Win +{ + + std::string GetCurrentWorkingDirectory() + { + char path[MAX_PATH]; + GetCurrentDirectory(MAX_PATH, path); + return path; + } + + void SetDllSearchDirectory(std::string path) + { + SetDllDirectory(path.c_str()); + } + +} \ No newline at end of file diff --git a/Editor/Win/Win.h b/Editor/Win/Win.h new file mode 100644 index 0000000..cbbba4c --- /dev/null +++ b/Editor/Win/Win.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +// windows 辅助函数 + +namespace Win +{ + + std::string GetCurrentWorkingDirectory(); + void SetDllSearchDirectory(std::string path); + +} -- cgit v1.1-26-g67d0