From 998a13b08c43b0813d1d4d38692ea7f8bd31c936 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 21 Oct 2021 16:11:45 +0800 Subject: *misc --- Editor/EditorMain.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'Editor/EditorMain.cpp') diff --git a/Editor/EditorMain.cpp b/Editor/EditorMain.cpp index 182a2c4..95937a7 100644 --- a/Editor/EditorMain.cpp +++ b/Editor/EditorMain.cpp @@ -15,24 +15,40 @@ void ErrorHandle(cc8* msg) log_error(std::string("[Lua] ") + msg); } +void OnRegisterFactoryClass(LuaBind::State& state, int cls, std::string clsName, std::string pkgName) +{ + // 填充类型的元数据 + lua_newtable(state); + int typeIdx = state.GetTop(); + state.Push("native"); + state.SetField(typeIdx, "mode"); + state.Push(clsName); + state.SetField(typeIdx, "name"); + state.Push(pkgName); + state.SetField(typeIdx, "package"); + lua_setfield(state, cls, "_type"); +} + void InitLuaState() { LuaBind::VM vm; vm.Setup(); vm.OpenLibs(); + + LuaBind::onRegisterFactoryClass = OnRegisterFactoryClass; + if (!SetupGameLabEditorScripting(vm.GetMainThread())) { log_error("Can't setup scripting."); } - LuaBind::State state = vm.GetMainState(); // https://stackoverflow.com/questions/21495901/loadlibrarya-and-relative-path/21495971 // ll_load装载dll,路径需要设置搜索路径 std::string workingDir = Win::GetCurrentWorkingDirectory(); Win::SetDllSearchDirectory(workingDir); + LuaBind::State state = vm.GetMainState(); state.DoFile("./boot.lua", ErrorHandle); - state.DoFile("./Scripts/EditorApplication.lua", ErrorHandle); } #ifdef GAMELAB_DEBUG -- cgit v1.1-26-g67d0