1 Star 0 Fork 6

代码库/ggesoeasy

forked from gite-hub/ggesoeasy 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.cpp 3.06 KB
一键复制 编辑 原始数据 按行查看 历史
cao-hub 提交于 2020-10-27 13:50 . .
#include <windows.h>
#include <time.h>
#include <fstream>
#include <sstream>
#include "libind/bind.h"
#include "gge.h"
#pragma comment(lib, "galaxy2d")
using namespace gge;
lua_State *L;
// CRITICAL_SECTION s_criticalSection;
// ccc_bind_declspec void cc_exit(int code) { PostQuitMessage(code); }
ccc_bind_declspec void cc_msgbox(const char* title, const char* text) { MessageBox(nullptr, Variant_Utf82Asc(text), Variant_Utf82Asc(title), MB_CANCELTRYCONTINUE); }
ccc_bind_declspec void cc_printf(const char* text) { printf("%s\n", Variant_Utf82Asc(text)); }
void registerMain(lua_State* ccc_register_state)
{
// ccc_register_func(cc_exit);
ccc_register_func(cc_msgbox);
ccc_register_func(cc_printf);
}
#if ccc_use_traceback
int traceback_index;
static bool errored = false;
int traceback(lua_State *state)
{
if (errored)
{
return 0;
}
errored = true;
const char *msg = nullptr;
if (lua_isstring(state, -1))
{
msg = lua_tostring(state, -1);
lua_pop(state, 1);
}
luaL_traceback(state, state, msg, 1);
if (lua_isstring(state, -1))
{
msg = lua_tostring(state, -1);
lua_pop(state, 1);
}
if (msg != nullptr)
{
cc_printf(msg);
cc_msgbox(__FUNCTION__, msg);
}
return 0;
}
#endif
HINSTANCE g_hInstance;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{
std::string scriptPath = "script/", mainlua;
if (__argc > 1)
{
scriptPath = __argv[1];
}
if (__argc > 2)
{
mainlua = scriptPath + __argv[2];
if (mainlua.find(".lua") == std::string::npos)
{
mainlua += ".lua";
}
std::ifstream ifile(mainlua, std::ios::binary);
if (ifile.is_open())
{
ifile.close();
}
else
{
mainlua.clear();
}
}
if (mainlua.empty())
{
mainlua = scriptPath + "bind/gmain.lua";
}
g_hInstance = hInst;
srand(time(nullptr));
gge::Random_Seed(time(nullptr));
// InitializeCriticalSection(&s_criticalSection);
L = ELuna::openLua();
registerGGE(L);
registerChild(L);
registerScheduler(L);
registerMain(L);
bool isConsole = AttachConsole(ATTACH_PARENT_PROCESS);
#ifdef _DEBUG
isConsole = isConsole || AllocConsole();
#endif
if(isConsole)
{
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
ccc_en_lock;
#if ccc_use_traceback
lua_pushcfunction(L, traceback);
traceback_index = lua_gettop(L);
#endif
lua_newtable(L);
lua_pushboolean(L, isConsole);
lua_setfield(L, -2, "console");
#if _DEBUG
lua_pushboolean(L, true);
#else
lua_pushboolean(L, false);
#endif
lua_setfield(L, -2, "debug");
lua_pushstring(L, scriptPath.c_str());
lua_setfield(L, -2, "scriptpath");
// lua_settable(L, -3);
lua_setglobal(L, "__easy");
#if ccc_use_traceback
auto r = luaL_loadfile(L, mainlua.c_str());
if (r == LUA_OK)
{
if (lua_pcall(L, 0, LUA_MULTRET, traceback_index) != LUA_OK)
{
auto msg = lua_tostring(L, -1);
if (msg != nullptr)
{
std::ostringstream ss;
ss << "top " << lua_gettop(L);
cc_msgbox(ss.str().c_str(), msg);
}
lua_pop(L, 1);
}
}
#else
luaL_dofile(L, mainlua.c_str());
#endif
ccc_un_lock;
gge::System_Start();
ELuna::closeLua(L);
gge::Engine_Release();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/code_ku/ggesoeasy.git
git@gitee.com:code_ku/ggesoeasy.git
code_ku
ggesoeasy
ggesoeasy
master

搜索帮助