aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jin/main.cpp29
-rw-r--r--src/lua/embed/embed.h14
2 files changed, 24 insertions, 19 deletions
diff --git a/src/jin/main.cpp b/src/jin/main.cpp
index 31e837f..f76bda7 100644
--- a/src/jin/main.cpp
+++ b/src/jin/main.cpp
@@ -47,38 +47,36 @@ std::string wstrtostr(const std::wstring &wstr)
}
#endif
-std::string BrowseFolder()
+bool BrowseFolder(string& cwd)
{
#ifdef _WIN32
- string path = EXECUTABLE_DIR;
IFileDialog* pfd = NULL;
DWORD dwFlags;
IShellItem* pItem = NULL;
HRESULT hr = CoInitialize(NULL);
- if (FAILED(hr)) goto End;
+ if (FAILED(hr)) return false;
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd));
- if (FAILED(hr)) goto End;
+ if (FAILED(hr)) return false;
pfd->SetTitle(DIALOG_TITLE);
hr = pfd->GetOptions(&dwFlags);
- if (FAILED(hr)) goto End;
+ if (FAILED(hr)) return false;
hr = pfd->SetOptions(dwFlags | FOS_PICKFOLDERS);
- if (FAILED(hr)) goto End;
+ if (FAILED(hr)) return false;
hr = pfd->Show(NULL);
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
- goto End;
+ return false;
hr = pfd->GetResult(&pItem);
- if (FAILED(hr)) goto End;
+ if (FAILED(hr)) return false;
LPWSTR filePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath);
- if (FAILED(hr)) goto End;
- path = wstrtostr(filePath);
+ if (FAILED(hr)) return false;
+ cwd = wstrtostr(filePath);
CoTaskMemFree(filePath);
pItem->Release();
pfd->Release();
CoUninitialize();
-End:
- return path;
+ return true;
#endif
}
@@ -90,9 +88,12 @@ int main(int argc, char* args[])
cwd = args[1];
#endif
else
- cwd = BrowseFolder();
+ {
+ if (!BrowseFolder(cwd))
+ return 0;
+ }
if (!cwd.empty())
load(cwd.c_str());
return 0;
-}// todo:main.luaĶȡ \ No newline at end of file
+} \ No newline at end of file
diff --git a/src/lua/embed/embed.h b/src/lua/embed/embed.h
index 054672c..7172a2c 100644
--- a/src/lua/embed/embed.h
+++ b/src/lua/embed/embed.h
@@ -18,10 +18,10 @@ namespace JinEngine
};
// Embed scripts.
- #include "scripts/graphics.lua.h"
- #include "scripts/keyboard.lua.h"
- #include "scripts/mouse.lua.h"
- #include "scripts/boot.lua.h"
+#include "scripts/graphics.lua.h"
+#include "scripts/keyboard.lua.h"
+#include "scripts/mouse.lua.h"
+#include "scripts/boot.lua.h"
// In order.
const jin_Embed scripts[] = {
@@ -35,7 +35,11 @@ namespace JinEngine
static void boot(lua_State* L)
{
for (int i = 0; scripts[i].file; ++i)
- embed(L, scripts[i].source, scripts[i].file);
+ {
+ const char* file = scripts[i].file, *source = scripts[i].source;
+ if (luax_loadbuffer(L, source, strlen(source), file) == 0)
+ lua_call(L, 0, 0);
+ }
}
} // namespace Embed