diff --git a/dl/script/dl_lua.cpp b/dl/script/dl_lua.cpp index 20e8babb..ad34faac 100644 --- a/dl/script/dl_lua.cpp +++ b/dl/script/dl_lua.cpp @@ -1,7 +1,31 @@ #include "dl_lua.h" +#define LUA_USE_APICHECK #include namespace dl { LuaScript* g_lua; + + LuaScript::LuaScript() + { + L = luaL_newstate(); + luaL_openlibs(L); + } + + LuaScript::~LuaScript() + { + lua_close(L); + } + + bool LuaScript::DoFile(std::string_view path_name) + { + int ret = luaL_dofile(L, path_name.data()); + if (ret) + { + log_err("lua do file失败!{}", path_name); + return false; + } + return true; + } + } \ No newline at end of file diff --git a/dl/script/dl_lua.h b/dl/script/dl_lua.h index 51e3daf8..0968b538 100644 --- a/dl/script/dl_lua.h +++ b/dl/script/dl_lua.h @@ -15,18 +15,20 @@ #include #include -#include - #include "dl_io.h" +struct lua_State; namespace dl { class LuaScript { public: - LuaScript() {} - ~LuaScript() {} + LuaScript(); + ~LuaScript(); + + bool DoFile(std::string_view path_name); private: + lua_State* L; }; extern LuaScript* g_lua; diff --git a/project/dl_console/main.cpp b/project/dl_console/main.cpp index 66d33b14..44f70fee 100644 --- a/project/dl_console/main.cpp +++ b/project/dl_console/main.cpp @@ -76,6 +76,7 @@ int main() log_msg("{}", v2.GetString()); g_lua = new LuaScript; + g_lua->DoFile("main.lua"); delete g_lua; Engine::Release(); diff --git a/project/dl_console/res/main.lua b/project/dl_console/res/main.lua new file mode 100644 index 00000000..6ca79a06 --- /dev/null +++ b/project/dl_console/res/main.lua @@ -0,0 +1 @@ +print "xxxx" \ No newline at end of file diff --git a/project/dl_midi b/project/dl_midi index ae96c815..1b9e55ce 160000 --- a/project/dl_midi +++ b/project/dl_midi @@ -1 +1 @@ -Subproject commit ae96c81546a6b83c2e1e7a6c2309015602cb813f +Subproject commit 1b9e55cefe63db27c4945bcc7ea38ad02ef39edd